@pkcprotocol/pkc-js 0.0.119 → 0.0.120

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.
Files changed (102) hide show
  1. package/README.md +2 -2
  2. package/dist/browser/community/community-client-manager.js +8 -2
  3. package/dist/browser/community/community-client-manager.js.map +1 -1
  4. package/dist/browser/errors.d.ts +2 -0
  5. package/dist/browser/errors.js +2 -0
  6. package/dist/browser/errors.js.map +1 -1
  7. package/dist/browser/generated-version.d.ts +1 -1
  8. package/dist/browser/generated-version.js +1 -1
  9. package/dist/browser/pages/page-sort-options.d.ts +1 -0
  10. package/dist/browser/pages/page-sort-options.js +7 -6
  11. package/dist/browser/pages/page-sort-options.js.map +1 -1
  12. package/dist/browser/pages/page-sort-scoring.d.ts +5 -1
  13. package/dist/browser/pages/page-sort-scoring.js +23 -13
  14. package/dist/browser/pages/page-sort-scoring.js.map +1 -1
  15. package/dist/browser/pages/types.d.ts +1 -1
  16. package/dist/browser/pkc-error.d.ts +1 -1
  17. package/dist/browser/publications/publication.d.ts +2 -0
  18. package/dist/browser/publications/publication.js +24 -1
  19. package/dist/browser/publications/publication.js.map +1 -1
  20. package/dist/browser/rpc/src/index.d.ts +4 -0
  21. package/dist/browser/rpc/src/index.js +74 -19
  22. package/dist/browser/rpc/src/index.js.map +1 -1
  23. package/dist/browser/runtime/node/community/db-handler.d.ts +2 -2
  24. package/dist/browser/runtime/node/community/db-handler.js +42 -58
  25. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  26. package/dist/browser/runtime/node/community/local-community/editing.d.ts +1 -0
  27. package/dist/browser/runtime/node/community/local-community/editing.js +25 -4
  28. package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
  29. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +7 -4
  30. package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  31. package/dist/browser/runtime/node/community/local-community/lifecycle.js +17 -4
  32. package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
  33. package/dist/browser/runtime/node/community/local-community/publication-validation.js +4 -0
  34. package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
  35. package/dist/browser/runtime/node/community/local-community.d.ts +4 -1
  36. package/dist/browser/runtime/node/community/local-community.js +12 -1
  37. package/dist/browser/runtime/node/community/local-community.js.map +1 -1
  38. package/dist/browser/runtime/node/community/page-generator.d.ts +0 -1
  39. package/dist/browser/runtime/node/community/page-generator.js.map +1 -1
  40. package/dist/browser/runtime/node/community/page-sorts/index.js +22 -4
  41. package/dist/browser/runtime/node/community/page-sorts/index.js.map +1 -1
  42. package/dist/browser/runtime/node/util.d.ts +4 -1
  43. package/dist/browser/runtime/node/util.js +41 -24
  44. package/dist/browser/runtime/node/util.js.map +1 -1
  45. package/dist/bundled/bundle-manifest.json +40 -40
  46. package/dist/bundled/challenges.js +1 -1
  47. package/dist/bundled/chunks/{helia-for-pkc-Cr90E9ul.js → helia-for-pkc-Dk9JTeUn.js} +33 -33
  48. package/dist/bundled/chunks/{local-community-DngOEreY.js → local-community-BbJyIuOc.js} +118 -101
  49. package/dist/bundled/chunks/{local-community-B-UbNa-z.js → local-community-BkZDlh4z.js} +1 -1
  50. package/dist/bundled/chunks/{node-BHLzTAo9.js → node-CsHuIZmP.js} +21 -5
  51. package/dist/bundled/chunks/{page-sort-scoring-Drqxj8Pi.js → page-sort-scoring-B2iu-tyC.js} +11 -7
  52. package/dist/bundled/chunks/{rpc-local-community-_ooAoNPM.js → rpc-local-community-DMDs0XGh.js} +60 -27
  53. package/dist/bundled/chunks/{util-B-JWgzlN.js → util-CXxGmK2P.js} +3 -1
  54. package/dist/bundled/chunks/{util-DX2ZJtU4.js → util-_DJ6MgmW.js} +1 -1
  55. package/dist/bundled/chunks/{validate-package-factories-BSmEBl_0.js → validate-package-factories-BpJjVrRb.js} +2 -2
  56. package/dist/bundled/index.js +1 -1
  57. package/dist/bundled/page-sorts.js +1 -1
  58. package/dist/bundled/rpc/src/index.js +56 -19
  59. package/dist/node/community/community-client-manager.js +8 -2
  60. package/dist/node/community/community-client-manager.js.map +1 -1
  61. package/dist/node/errors.d.ts +2 -0
  62. package/dist/node/errors.js +2 -0
  63. package/dist/node/errors.js.map +1 -1
  64. package/dist/node/generated-version.d.ts +1 -1
  65. package/dist/node/generated-version.js +1 -1
  66. package/dist/node/pages/page-sort-options.d.ts +1 -0
  67. package/dist/node/pages/page-sort-options.js +7 -6
  68. package/dist/node/pages/page-sort-options.js.map +1 -1
  69. package/dist/node/pages/page-sort-scoring.d.ts +5 -1
  70. package/dist/node/pages/page-sort-scoring.js +23 -13
  71. package/dist/node/pages/page-sort-scoring.js.map +1 -1
  72. package/dist/node/pages/types.d.ts +1 -1
  73. package/dist/node/pkc-error.d.ts +1 -1
  74. package/dist/node/publications/publication.d.ts +2 -0
  75. package/dist/node/publications/publication.js +24 -1
  76. package/dist/node/publications/publication.js.map +1 -1
  77. package/dist/node/rpc/src/index.d.ts +4 -0
  78. package/dist/node/rpc/src/index.js +74 -19
  79. package/dist/node/rpc/src/index.js.map +1 -1
  80. package/dist/node/runtime/node/community/db-handler.d.ts +2 -2
  81. package/dist/node/runtime/node/community/db-handler.js +42 -58
  82. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  83. package/dist/node/runtime/node/community/local-community/editing.d.ts +1 -0
  84. package/dist/node/runtime/node/community/local-community/editing.js +25 -4
  85. package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
  86. package/dist/node/runtime/node/community/local-community/ipns-publishing.js +7 -4
  87. package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
  88. package/dist/node/runtime/node/community/local-community/lifecycle.js +17 -4
  89. package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
  90. package/dist/node/runtime/node/community/local-community/publication-validation.js +4 -0
  91. package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
  92. package/dist/node/runtime/node/community/local-community.d.ts +4 -1
  93. package/dist/node/runtime/node/community/local-community.js +12 -1
  94. package/dist/node/runtime/node/community/local-community.js.map +1 -1
  95. package/dist/node/runtime/node/community/page-generator.d.ts +0 -1
  96. package/dist/node/runtime/node/community/page-generator.js.map +1 -1
  97. package/dist/node/runtime/node/community/page-sorts/index.js +22 -4
  98. package/dist/node/runtime/node/community/page-sorts/index.js.map +1 -1
  99. package/dist/node/runtime/node/util.d.ts +4 -1
  100. package/dist/node/runtime/node/util.js +41 -24
  101. package/dist/node/runtime/node/util.js.map +1 -1
  102. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { _ as getEquivalentCommunityAddresses, vn as PageSortFileSchema } from "./util-B-JWgzlN.js";
1
+ import { _ as getEquivalentCommunityAddresses, vn as PageSortFileSchema, xn as isStringDomain } from "./util-CXxGmK2P.js";
2
2
  //#region dist/node/pages/page-sort-scoring.js
3
3
  function validatePageSortFile(rawFile) {
4
4
  const validated = PageSortFileSchema.parse(rawFile);
@@ -9,16 +9,21 @@ function validatePageSortFile(rawFile) {
9
9
  ...raw.validatePageSortSettings ? { validatePageSortSettings: raw.validatePageSortSettings } : {}
10
10
  };
11
11
  }
12
+ function createCommunityIdentityRowFilter(communityAddress) {
13
+ if (isStringDomain(communityAddress)) {
14
+ const equivalentNames = new Set(getEquivalentCommunityAddresses(communityAddress));
15
+ return (comment) => !comment.communityName || equivalentNames.has(comment.communityName);
16
+ }
17
+ return (comment) => !comment.communityPublicKey || comment.communityPublicKey === communityAddress;
18
+ }
12
19
  function applyPageSortExclusions({ comments, exclusions, communityAddress }) {
13
- const equivalentAddresses = communityAddress ? new Set(getEquivalentCommunityAddresses(communityAddress)) : void 0;
20
+ const belongsToCommunity = createCommunityIdentityRowFilter(communityAddress);
14
21
  return comments.filter(({ comment, commentUpdate }) => {
22
+ if (!belongsToCommunity(comment)) return false;
15
23
  if (exclusions.excludeRemovedComments && commentUpdate.removed === true) return false;
16
24
  if (exclusions.excludeDeletedComments && commentUpdate.edit?.deleted === true) return false;
17
25
  if (exclusions.excludeCommentWithApprovedFalse && commentUpdate.approved === false) return false;
18
26
  if (exclusions.excludeCommentPendingApproval && commentUpdate.pendingApproval === true) return false;
19
- if (exclusions.excludeCommentsWithDifferentCommunityAddress && equivalentAddresses) {
20
- if (!((comment.communityPublicKey ? equivalentAddresses.has(comment.communityPublicKey) : false) || (comment.communityName ? equivalentAddresses.has(comment.communityName) : false))) return false;
21
- }
22
27
  return true;
23
28
  });
24
29
  }
@@ -29,8 +34,7 @@ function filterRepliesForPageSort({ replies, communityAddress }) {
29
34
  excludeRemovedComments: false,
30
35
  excludeDeletedComments: false,
31
36
  excludeCommentWithApprovedFalse: false,
32
- excludeCommentPendingApproval: false,
33
- excludeCommentsWithDifferentCommunityAddress: true
37
+ excludeCommentPendingApproval: false
34
38
  },
35
39
  communityAddress
36
40
  });
@@ -1,7 +1,7 @@
1
1
  import { i as __toESM, n as __exportAll, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { $ as shortifyAddress, $n as CreateCommentEditOptionsWithRefinementSchema, $t as CommentModerationPubsubMessagePublicationSchema, An as CommentIpfsSchema, Ar as PKCError, B as raceAgainstAbort, Br as literal, Bt as DecryptedChallengeVerificationSchema, C as interruptibleSleep, Cn as VoteChallengeRequestToEncryptSchema, Cr as e$4, D as isIpfsPath, Dr as FailedToFetchCommunityFromGatewaysError, Dt as pTimeout, E as isIpfsCid, En as VoteSignedPropertyNames, Er as FailedToFetchCommentUpdateFromGatewaysError, Ft as ChallengeVerificationMessageSignedPropertyNames, G as removeNullUndefinedEmptyObjectsValuesRecursively, Gn as PageIpfsSchema, Gt as PKCUserOptionsSchema, Hn as CreateCommentOptionsWithRefinementSchema, Hr as object, Ht as NameResolverSerializedSchema, I as isRequestPubsubPublicationOfPost, In as CommentUpdateForChallengeVerificationSignedPropertyNames, Ir as _enum, It as DecryptedChallengeAnswerSchema, Kn as isReservedObjectKey, L as isRequestPubsubPublicationOfReply, Ln as CommentUpdateReservedFields, Lr as array, Mn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Mr as logger_default, Nn as CommentSignedPropertyNames, Nr as require_supports_color, Nt as ChallengeRequestMessageSignedPropertyNames, O as isIpns, On as CommentChallengeRequestToEncryptSchema, Or as FailedToFetchGenericIpfsFromGatewaysError, Pn as CommentUpdateChallengeReservedFieldNames, Pr as require_ms$1, Qt as CommentModerationChallengeRequestToEncryptSchema, R as pubsubTopicToDhtKey, Rn as CommentUpdateSchema, Rr as boolean, S as hideClassPrivateProps, Sn as CreateVoteUserOptionsWithRefinementSchema, Sr as t$9, St as untrackStartedCommunity, T as isAbortError, Tr as FailedToFetchCommentIpfsFromGatewaysError, Tt as require_sha256$1, Un as GetPageParamSchema, Ur as record, Ut as PKCParsedOptionsSchema, Vr as number, Vt as NameResolveCacheOptionsSchema, Wn as ModQueuePageIpfsSchema, Wr as string, Wt as PKCUserOptionBaseSchema, Xt as CommunityEditPubsubMessagePublicationSchema, Yn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Yt as CommunityEditPublicationSignedPropertyNames, Zn as CommentEditSignedPropertyNames, Zt as CreateCommunityEditPublicationOptionsWithRefinementSchema, _n as PageSortFileFactorySchema, _r as r$8, _t as refreshTrackedCommunityAliases, an as ChallengeFileSchema, ar as CidStringSchema, bn as RpcRemoteCommunityUpdateEventResultSchema, br as r$7, cn as CommunityEditOptionsSchema, cr as CreateSignerSchema, d as derivePublicationFromChallengeRequest, dn as CommunityIpfsSchema, dr as n$10, er as AuthorAddressSchema, et as shortifyCid, f as doesDomainAddressHaveCapitalLetter, fn as CommunitySignedPropertyNames, ft as findUpdatingCommunity, gn as ExportCommunityModLogsOptionsSchema, gr as t$11, hn as CreateRpcCommunityFunctionArgumentSchema, hr as e$5, in as ChallengeFileFactorySchema, ir as CidPathSchema, it as timestamp, jr as messages, jt as ChallengeMessageSignedPropertyNames, k as isIpnsPath, kn as CommentIpfsReservedFields, kr as FailedToFetchPageIpfsFromGatewaysError, kt as ChallengeAnswerMessageSignedPropertyNames, l as createAbortError, ln as CommunityExportRecordsSchema, lr as n$9, m as fetchAndValidateIpnsRecordFromGateway, mn as CreateRemoteCommunityFunctionArgumentSchema, mr as e$6, nn as CommentModerationsTableRowSchema, or as CommunityAddressSchema, p as extractNetworkErrorDetails, pn as CreateNewLocalCommunityUserOptionsSchema, pr as t$13, qn as CommentEditChallengeRequestToEncryptSchema, qt as CommunityEditPublicationChallengeRequestToEncryptSchema, r as calculateIpfsCidV0, rn as CreateCommentModerationOptionsWithRefinementSchema, rr as ChallengeAnswersSchema, rt as throwIfAbortSignalAborted, sn as CommunityChallengeSettingSchema, sr as CommunityAuthorChallengeReservedFieldNames, t as areEquivalentCommunityAddresses, tn as CommentModerationSignedPropertyNames, tr as AuthorCommentIpfsReservedFields, tt as sleepUntilTimeoutOrAbort, u as deepMergeRuntimeFields, un as CommunityIpfsReservedFields, ut as findStartedCommunity, vn as PageSortFileSchema, vr as t$12, w as ipnsNameToIpnsOverPubsubTopic, wn as VotePubsubMessagePublicationSchema, wr as require_retry$1, wt as untrackUpdatingCommunity, x as hasTransientNetworkErrorCode, xn as isStringDomain, xr as t$10, xt as trackUpdatingCommunity, yr as n$8, yt as trackStartedCommunity, zn as CommentUpdateSignedPropertyNames, zr as custom, zt as DecryptedChallengeSchema } from "./util-B-JWgzlN.js";
2
+ import { $ as shortifyAddress, $n as CreateCommentEditOptionsWithRefinementSchema, $t as CommentModerationPubsubMessagePublicationSchema, An as CommentIpfsSchema, Ar as PKCError, B as raceAgainstAbort, Br as literal, Bt as DecryptedChallengeVerificationSchema, C as interruptibleSleep, Cn as VoteChallengeRequestToEncryptSchema, Cr as e$4, D as isIpfsPath, Dr as FailedToFetchCommunityFromGatewaysError, Dt as pTimeout, E as isIpfsCid, En as VoteSignedPropertyNames, Er as FailedToFetchCommentUpdateFromGatewaysError, Ft as ChallengeVerificationMessageSignedPropertyNames, G as removeNullUndefinedEmptyObjectsValuesRecursively, Gn as PageIpfsSchema, Gt as PKCUserOptionsSchema, Hn as CreateCommentOptionsWithRefinementSchema, Hr as object, Ht as NameResolverSerializedSchema, I as isRequestPubsubPublicationOfPost, In as CommentUpdateForChallengeVerificationSignedPropertyNames, Ir as _enum, It as DecryptedChallengeAnswerSchema, Kn as isReservedObjectKey, L as isRequestPubsubPublicationOfReply, Ln as CommentUpdateReservedFields, Lr as array, Mn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Mr as logger_default, Nn as CommentSignedPropertyNames, Nr as require_supports_color, Nt as ChallengeRequestMessageSignedPropertyNames, O as isIpns, On as CommentChallengeRequestToEncryptSchema, Or as FailedToFetchGenericIpfsFromGatewaysError, Pn as CommentUpdateChallengeReservedFieldNames, Pr as require_ms$1, Qt as CommentModerationChallengeRequestToEncryptSchema, R as pubsubTopicToDhtKey, Rn as CommentUpdateSchema, Rr as boolean, S as hideClassPrivateProps, Sn as CreateVoteUserOptionsWithRefinementSchema, Sr as t$9, St as untrackStartedCommunity, T as isAbortError, Tr as FailedToFetchCommentIpfsFromGatewaysError, Tt as require_sha256$1, Un as GetPageParamSchema, Ur as record, Ut as PKCParsedOptionsSchema, Vr as number, Vt as NameResolveCacheOptionsSchema, Wn as ModQueuePageIpfsSchema, Wr as string, Wt as PKCUserOptionBaseSchema, Xt as CommunityEditPubsubMessagePublicationSchema, Yn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Yt as CommunityEditPublicationSignedPropertyNames, Zn as CommentEditSignedPropertyNames, Zt as CreateCommunityEditPublicationOptionsWithRefinementSchema, _n as PageSortFileFactorySchema, _r as r$8, _t as refreshTrackedCommunityAliases, an as ChallengeFileSchema, ar as CidStringSchema, bn as RpcRemoteCommunityUpdateEventResultSchema, br as r$7, cn as CommunityEditOptionsSchema, cr as CreateSignerSchema, d as derivePublicationFromChallengeRequest, dn as CommunityIpfsSchema, dr as n$10, er as AuthorAddressSchema, et as shortifyCid, f as doesDomainAddressHaveCapitalLetter, fn as CommunitySignedPropertyNames, ft as findUpdatingCommunity, gn as ExportCommunityModLogsOptionsSchema, gr as t$11, hn as CreateRpcCommunityFunctionArgumentSchema, hr as e$5, in as ChallengeFileFactorySchema, ir as CidPathSchema, it as timestamp, jr as messages, jt as ChallengeMessageSignedPropertyNames, k as isIpnsPath, kn as CommentIpfsReservedFields, kr as FailedToFetchPageIpfsFromGatewaysError, kt as ChallengeAnswerMessageSignedPropertyNames, l as createAbortError, ln as CommunityExportRecordsSchema, lr as n$9, m as fetchAndValidateIpnsRecordFromGateway, mn as CreateRemoteCommunityFunctionArgumentSchema, mr as e$6, nn as CommentModerationsTableRowSchema, or as CommunityAddressSchema, p as extractNetworkErrorDetails, pn as CreateNewLocalCommunityUserOptionsSchema, pr as t$13, qn as CommentEditChallengeRequestToEncryptSchema, qt as CommunityEditPublicationChallengeRequestToEncryptSchema, r as calculateIpfsCidV0, rn as CreateCommentModerationOptionsWithRefinementSchema, rr as ChallengeAnswersSchema, rt as throwIfAbortSignalAborted, sn as CommunityChallengeSettingSchema, sr as CommunityAuthorChallengeReservedFieldNames, t as areEquivalentCommunityAddresses, tn as CommentModerationSignedPropertyNames, tr as AuthorCommentIpfsReservedFields, tt as sleepUntilTimeoutOrAbort, u as deepMergeRuntimeFields, un as CommunityIpfsReservedFields, ut as findStartedCommunity, vn as PageSortFileSchema, vr as t$12, w as ipnsNameToIpnsOverPubsubTopic, wn as VotePubsubMessagePublicationSchema, wr as require_retry$1, wt as untrackUpdatingCommunity, x as hasTransientNetworkErrorCode, xn as isStringDomain, xr as t$10, xt as trackUpdatingCommunity, yr as n$8, yt as trackStartedCommunity, zn as CommentUpdateSignedPropertyNames, zr as custom, zt as DecryptedChallengeSchema } from "./util-CXxGmK2P.js";
3
3
  import { t as all } from "./src-CYIMjhjK.js";
4
- import { s as validatePageSortFile } from "./page-sort-scoring-Drqxj8Pi.js";
4
+ import { s as validatePageSortFile } from "./page-sort-scoring-B2iu-tyC.js";
5
5
  import { createHash } from "node:crypto";
6
6
  import { pathToFileURL } from "node:url";
7
7
  import dns from "node:dns";
@@ -92178,22 +92178,38 @@ const setNativeFunctions = (newNativeFunctions) => {
92178
92178
  if (!newNativeFunctions) throw Error(`User passed an undefined object to setNativeFunctions`);
92179
92179
  for (const i in newNativeFunctions) nativeFunctions[i] = newNativeFunctions[i];
92180
92180
  };
92181
- const deleteOldCommunityInWindows = async (subPath, pkc) => {
92181
+ const WINDOWS_FILE_BUSY_ERROR_CODES = ["EBUSY", "EPERM"];
92182
+ const deleteOldCommunityInWindows = async (subPath, pkc, { timeoutMs = 1e4 } = {}) => {
92182
92183
  const log = logger_default("pkc-js:community:deleteStaleCommunityInWindows");
92183
92184
  const communityAddress = path.basename(subPath);
92184
- await new Promise((resolve) => setTimeout(resolve, 1e4));
92185
- try {
92185
+ const deadline = Date.now() + timeoutMs;
92186
+ for (let retryDelayMs = 50;; retryDelayMs = Math.min(retryDelayMs * 2, 1e3)) try {
92186
92187
  await promises.rm(subPath, { force: true });
92187
92188
  log(`Succeeded in deleting old community (${communityAddress})`);
92189
+ return;
92188
92190
  } catch (e) {
92189
- log.error(`Failed to delete old community (${communityAddress}). Restarting the node process or daemon should make this error disappear`, e);
92190
- const storageKey = STORAGE_KEYS[STORAGE_KEYS.PERSISTENT_DELETED_COMMUNITIES];
92191
- const communitiesThatWeFailedToDelete = await pkc._storage.getItem(storageKey) || [];
92192
- if (!communitiesThatWeFailedToDelete.includes(communityAddress)) communitiesThatWeFailedToDelete.push(communityAddress);
92193
- await pkc._storage.setItem(storageKey, communitiesThatWeFailedToDelete);
92194
- log(`Updated persistent deleted communities in storage`, communitiesThatWeFailedToDelete);
92191
+ const code = e.code;
92192
+ if (!code || !WINDOWS_FILE_BUSY_ERROR_CODES.includes(code) || Date.now() + retryDelayMs >= deadline) {
92193
+ await recordCommunityThatFailedToBeDeleted({
92194
+ communityAddress,
92195
+ pkc,
92196
+ error: e,
92197
+ log
92198
+ });
92199
+ return;
92200
+ }
92201
+ log(`Old community (${communityAddress}) is still busy (${code}), retrying in ${retryDelayMs}ms`);
92202
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
92195
92203
  }
92196
92204
  };
92205
+ async function recordCommunityThatFailedToBeDeleted({ communityAddress, pkc, error, log }) {
92206
+ log.error(`Failed to delete old community (${communityAddress}). Restarting the node process or daemon should make this error disappear`, error);
92207
+ const storageKey = STORAGE_KEYS[STORAGE_KEYS.PERSISTENT_DELETED_COMMUNITIES];
92208
+ const communitiesThatWeFailedToDelete = await pkc._storage.getItem(storageKey) || [];
92209
+ if (!communitiesThatWeFailedToDelete.includes(communityAddress)) communitiesThatWeFailedToDelete.push(communityAddress);
92210
+ await pkc._storage.setItem(storageKey, communitiesThatWeFailedToDelete);
92211
+ log(`Updated persistent deleted communities in storage`, communitiesThatWeFailedToDelete);
92212
+ }
92197
92213
  async function tryToDeleteCommunitiesThatFailedToBeDeletedBefore(pkc, log) {
92198
92214
  const deletedPersistentCommunities = await pkc._storage.getItem(STORAGE_KEYS[STORAGE_KEYS.PERSISTENT_DELETED_COMMUNITIES]);
92199
92215
  if (Array.isArray(deletedPersistentCommunities)) {
@@ -92225,6 +92241,10 @@ async function tryToDeleteCommunitiesThatFailedToBeDeletedBefore(pkc, log) {
92225
92241
  }
92226
92242
  }
92227
92243
  }
92244
+ function refreshCommunitiesList(pkc) {
92245
+ const currentCommunities = listCommunitiesSync(pkc);
92246
+ if (stringify(currentCommunities) !== stringify(pkc.communities)) pkc.emit("communitieschange", currentCommunities);
92247
+ }
92228
92248
  function listCommunitiesSync(pkc) {
92229
92249
  const log = logger_default("pkc-js:listCommunitiesSync");
92230
92250
  if (typeof pkc.dataPath !== "string") throw Error("pkc.dataPath needs to be defined to listCommunities");
@@ -92449,8 +92469,7 @@ async function monitorCommunitiesDirectory(pkc) {
92449
92469
  "-wal"
92450
92470
  ];
92451
92471
  let isProcessingChange = false;
92452
- const initialCommunities = listCommunitiesSync(pkc);
92453
- if (stringify(initialCommunities) !== stringify(pkc.communities)) pkc.emit("communitieschange", initialCommunities);
92472
+ refreshCommunitiesList(pkc);
92454
92473
  watch(communitiesPath, {
92455
92474
  signal: watchAbortController.signal,
92456
92475
  persistent: false
@@ -92459,8 +92478,7 @@ async function monitorCommunitiesDirectory(pkc) {
92459
92478
  if (isProcessingChange) return;
92460
92479
  isProcessingChange = true;
92461
92480
  try {
92462
- const currentCommunities = listCommunitiesSync(pkc);
92463
- if (stringify(currentCommunities) !== stringify(pkc.communities)) pkc.emit("communitieschange", currentCommunities);
92481
+ refreshCommunitiesList(pkc);
92464
92482
  } catch (error) {} finally {
92465
92483
  isProcessingChange = false;
92466
92484
  }
@@ -124842,13 +124860,15 @@ var CommunityClientsManager = class extends PKCClientsManager {
124842
124860
  if (subRes?.community) {
124843
124861
  const identityPublicKey = subRes.community.anchor?.publicKey ?? ipnsName;
124844
124862
  const anchorIdentityAddress = subRes.community.name || identityPublicKey;
124845
- this._pkc._memCaches.communityForPublishing.set(anchorIdentityAddress, {
124863
+ const communityForPublishing = {
124846
124864
  encryption: subRes.community.encryption,
124847
124865
  pubsubTopic: subRes.community.pubsubTopic,
124848
124866
  address: anchorIdentityAddress,
124849
124867
  publicKey: identityPublicKey,
124850
124868
  name: subRes.community.name
124851
- });
124869
+ };
124870
+ this._pkc._memCaches.communityForPublishing.set(anchorIdentityAddress, communityForPublishing);
124871
+ if (anchorIdentityAddress !== identityPublicKey) this._pkc._memCaches.communityForPublishing.set(identityPublicKey, communityForPublishing);
124852
124872
  }
124853
124873
  return subRes;
124854
124874
  });
@@ -128923,9 +128943,9 @@ const PAGE_SORT_EXCLUSION_OPTION_NAMES = Object.freeze([
128923
128943
  "excludeRemovedComments",
128924
128944
  "excludeDeletedComments",
128925
128945
  "excludeCommentPendingApproval",
128926
- "excludeCommentWithApprovedFalse",
128927
- "excludeCommentsWithDifferentCommunityAddress"
128946
+ "excludeCommentWithApprovedFalse"
128928
128947
  ]);
128948
+ const REMOVED_PAGE_SORT_OPTION_NAMES = Object.freeze(["excludeCommentsWithDifferentCommunityAddress"]);
128929
128949
  const RESERVED_PAGE_SORT_OPTION_NAMES = Object.freeze([
128930
128950
  "maxAge",
128931
128951
  "pinnedFirst",
@@ -128937,16 +128957,14 @@ const DEFAULT_RESERVED_OPTIONS = Object.freeze({
128937
128957
  excludeRemovedComments: "true",
128938
128958
  excludeDeletedComments: "true",
128939
128959
  excludeCommentPendingApproval: "true",
128940
- excludeCommentWithApprovedFalse: "true",
128941
- excludeCommentsWithDifferentCommunityAddress: "true"
128960
+ excludeCommentWithApprovedFalse: "true"
128942
128961
  },
128943
128962
  replies: {
128944
128963
  pinnedFirst: "true",
128945
128964
  excludeRemovedComments: "false",
128946
128965
  excludeDeletedComments: "false",
128947
128966
  excludeCommentPendingApproval: "true",
128948
- excludeCommentWithApprovedFalse: "false",
128949
- excludeCommentsWithDifferentCommunityAddress: "true"
128967
+ excludeCommentWithApprovedFalse: "false"
128950
128968
  }
128951
128969
  });
128952
128970
  function parseBooleanOption(raw) {
@@ -129243,6 +129261,20 @@ async function loadPageSortFile({ pageSortSettings, pkc }) {
129243
129261
  }
129244
129262
  return file;
129245
129263
  }
129264
+ function withoutRemovedPageSortOptions(options, pageSortName) {
129265
+ const removed = Object.keys(options).filter((optionName) => REMOVED_PAGE_SORT_OPTION_NAMES.includes(optionName));
129266
+ if (removed.length === 0) return options;
129267
+ logger_default("pkc-js:local-community:page-sorts:resolve")(`Ignoring removed page sort options ${removed.join(", ")} of sort ${pageSortName}; the community identity rule now always applies (issue #401)`);
129268
+ return Object.fromEntries(Object.entries(options).filter(([optionName]) => !removed.includes(optionName)));
129269
+ }
129270
+ function withoutRemovedPageSortSettingOptions(pageSortSettings) {
129271
+ if (!pageSortSettings.options) return pageSortSettings;
129272
+ const options = withoutRemovedPageSortOptions(pageSortSettings.options, describePageSort(pageSortSettings));
129273
+ return options === pageSortSettings.options ? pageSortSettings : {
129274
+ ...pageSortSettings,
129275
+ options
129276
+ };
129277
+ }
129246
129278
  function resolveOneEntry({ pageSortSettings, file, scope, pageSortIndex }) {
129247
129279
  const baseDetails = {
129248
129280
  scope,
@@ -129277,11 +129309,11 @@ function resolveOneEntry({ pageSortSettings, file, scope, pageSortIndex }) {
129277
129309
  offendingOption: optionName
129278
129310
  }) };
129279
129311
  }
129280
- const options = {
129312
+ const options = withoutRemovedPageSortOptions({
129281
129313
  ...DEFAULT_RESERVED_OPTIONS[scope],
129282
129314
  ...file.defaultOptions,
129283
129315
  ...entryOptions
129284
- };
129316
+ }, baseDetails.pageSortName);
129285
129317
  let reserved;
129286
129318
  try {
129287
129319
  reserved = parseReservedPageSortOptions(options);
@@ -129322,7 +129354,8 @@ async function resolvePageSortsAndCollectFailures({ pagesSettings, pkc, tolerate
129322
129354
  };
129323
129355
  for (const { scope, entries } of entriesOfEveryScope(pagesSettings)) {
129324
129356
  const seenSortNames = /* @__PURE__ */ new Set();
129325
- for (const [pageSortIndex, pageSortSettings] of entries.entries()) {
129357
+ for (const [pageSortIndex, storedPageSortSettings] of entries.entries()) {
129358
+ const pageSortSettings = withoutRemovedPageSortSettingOptions(storedPageSortSettings);
129326
129359
  const pageSortName = describePageSort(pageSortSettings);
129327
129360
  let file;
129328
129361
  try {
@@ -130092,4 +130125,4 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
130092
130125
  }
130093
130126
  };
130094
130127
  //#endregion
130095
- export { parseCidStringSchemaWithPKCErrorIfItFails as $, backupCommunityDb as $n, require_lib as $t, findCommentInParsedPages as A, verifyCommunity as An, STORAGE_KEYS as Ar, parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as At, InflightFetchManager as B, buildRuntimeCommunityFields as Bn, RpcExportCommunityModLogsParamSchema as Bt, RepliesPages as C, verifyChallengeRequest as Cn, t$7 as Cr, parseDecryptedChallengeVerification as Ct, extractCommunityRuntimeFieldsFromParsedPages as D, verifyCommentModeration as Dn, NAME_RESOLVED_FALSE_TTL_MS as Dr, parseRpcCommentEventWithPKCErrorIfItFails as Dt, buildPagesRuntimeFields as E, verifyCommentIpfs as En, MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE as Er, parsePKCUserOptionsSchemaWithPKCErrorIfItFails as Et, collectCrosspostAuthorsToResolve as F, getAuthorNameFromRuntime as Fn, RpcCidParamSchema as Ft, decodeRpcChallengeAnswerPubsubMsg as G, decode as Gn, RpcFetchCidResultSchema as Gt, pRetry as H, getCommunityNameFromWire$1 as Hn, RpcExportCommunityParamSchema as Ht, extractCrosspostRuntimeFields as I, getAuthorNameFromWire as In, RpcCommentRepliesPageParamSchema as It, decodeRpcChallengeVerificationPubsubMsg as J, getIpfsKeyFromPrivateKey as Jn, RpcPublishedAnchorRecordResultSchema as Jt, decodeRpcChallengePubsubMsg as K, encode as Kn, RpcPublishAnchorRecordParamSchema as Kt, stripNameResolvedFromCrosspost as L, normalizeCreatePublicationAuthor as Ln, RpcCommunityIdentifierParamSchema as Lt, parseRawPages as M, verifyVote as Mn, nativeFunctions$1 as Mr, RpcAnchorPublishPreparationResultSchema as Mt, applyNameResolvedCacheToCrosspost as N, buildRuntimeAuthor as Nn, require_undici as Nr, RpcAuthorNameParamSchema as Nt, findCommentInPageInstance as O, verifyCommentPubsubMessage as On, NAME_RESOLVED_TRUE_TTL_MS as Or, parseRpcCommentUpdateEventWithPKCErrorIfItFails as Ot, cloneCrosspostForRuntime as P, cleanWireAuthor as Pn, RpcCancelExportParamSchema as Pt, createSchemaRowParser as Q, BackupAbortError as Qn, RpcUnsubscribeParamSchema as Qt, PKCClientsManager as R, crosspostChainDepthUpTo as Rn, RpcCommunityPageParamSchema as Rt, KeyvBetterSqlite3 as S, verifyChallengeMessage as Sn, n$6 as Sr, parseDecryptedChallengeAnswerWithPKCErrorIfItFails as St, buildPageRuntimeFields as T, verifyCommentEdit as Tn, stringify as Tr, parseJsonWithPKCErrorIfFails as Tt, pLimit as U, getCommunityPublicKeyFromWire as Un, RpcExportCommunityResultSchema as Ut, InflightResourceTypes as V, getCommunityAddressFromRecord as Vn, RpcExportCommunityModLogsResultSchema as Vt, PKCTypedEmitter as W, normalizeCommunityInputFromCommunity as Wn, RpcFetchCidParamSchema as Wt, coerceSchemaRowJson as X, getPKCAddressFromPublicKeySync as Xn, RpcSubscriptionIdResultSchema as Xt, coerceSchemaRowBoolean as Y, getPKCAddressFromPublicKey as Yn, RpcResolveAuthorNameResultSchema as Yt, collectSchemaRowCoercions as Z, getPublicKeyFromPrivateKey as Zn, RpcSuccessResultSchema as Zt, createAuthorIdentityMatcher as _, signCommentUpdateForChallengeVerification as _n, t$2 as _r, parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails as _t, generatePagesReportingFailedSorts as a, encryptEd25519AesGcm as an, deriveDbPosts as ar, parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails as at, RemoteCommunity as b, signVote as bn, t$5 as br, parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails as bt, resolvePageSortsOrThrow as c, cleanUpBeforePublishing as cn, getDefaultDataPath as cr, parseCommunityAddressWithPKCErrorIfItFails as ct, getChallengeVerification as d, signChallengeRequest as dn, listCommunitiesSync as dr, parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails as dt, SignerWithPublicKeyAddress as en, calculateExpectedSignatureSize as er, parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as et, getCommunityChallengeFromCommunityChallengeSettings as f, signChallengeVerification as fn, monitorCommunitiesDirectory as fr, parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails as ft, authorNameResolveFailureReason as g, signCommentUpdate as gn, tryToDeleteCommunitiesThatFailedToBeDeletedBefore as gr, parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails as gt, authorIdentityMatcherForRequest as h, signCommentModeration as hn, setNativeFunctions as hr, parseCreateCommentOptionsSchemaWithPKCErrorIfItFails as ht, derivePublicPageSorts as i, decryptEd25519AesGcmPublicKeyBuffer as in, deriveCommentIpfsFromCommentTableRow as ir, parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as it, iterateOverPageCidsToFindAllCids as j, verifyCommunityEdit as jn, require_lodash_merge as jr, parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails as jt, findCommentInPageInstanceRecursively as k, verifyCommentUpdate as kn, NAME_RESOLVE_FAILED_RETRY_FLOOR_MS as kr, parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails as kt, pkcJsPageSorts as l, signChallengeAnswer as ln, getThumbnailPropsOfLink as lr, parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as lt, pkcJsChallenges as m, signCommentEdit as mn, resolveDbPostsCidRefs as mr, parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails as mt, RpcRemoteCommunity as n, createAnchorIpnsRecord as nn, createKuboRpcClient as nr, parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails as nt, loadPageSortsForStartedCommunity as o, encryptEd25519AesGcmPublicKeyBuffer as on, deriveDbReplies as or, parseCommentPubsubMessagePublicationWithPKCErrorIfItFails as ot, loadChallengeFileFromCommunityChallengeSettings as p, signComment as pn, moveCommunityDbToDeletedDirectory as pr, parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails as pt, decodeRpcChallengeRequestPubsubMsg as q, getBufferedPKCAddressFromPublicKey as qn, RpcPublishChallengeAnswersParamSchema as qt, computePageSortsFingerprint as r, decryptEd25519AesGcm as rn, deleteOldCommunityInWindows as rr, parseCommentIpfsSchemaWithPKCErrorIfItFails as rt, lookupPageSortFactories as s, _validateSignatureOfPKCRecord as sn, getDefaultCommunityDbConfig as sr, parseCommentUpdateSchemaWithPKCErrorIfItFails as st, RpcLocalCommunity as t, createSigner as tn, calculateInlineRepliesBudget as tr, parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as tt, deriveCommunityChallengesOrThrow as u, signChallengeMessage as un, importSignerIntoKuboNode as ur, parseCommunityEditOptionsSchemaWithPKCErrorIfItFails as ut, TrackedInstanceRegistry as v, signCommunity as vn, t$4 as vr, parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails as vt, TIMEFRAMES_TO_SECONDS as w, verifyChallengeVerification as wn, t$8 as wr, parseDecryptedChallengeWithPKCErrorIfItFails as wt, MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS as x, verifyChallengeAnswer as xn, n$5 as xr, parseCreateVoteOptionsSchemaWithPKCErrorIfItFails as xt, LRUCache as y, signCommunityEdit as yn, r as yr, parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails as yt, GenericStateClient as z, effectiveMaxCrosspostDepth as zn, RpcEditCommunityParamSchema as zt };
130128
+ export { parseCidStringSchemaWithPKCErrorIfItFails as $, backupCommunityDb as $n, require_lib as $t, findCommentInParsedPages as A, verifyCommunity as An, NAME_RESOLVE_FAILED_RETRY_FLOOR_MS as Ar, parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as At, InflightFetchManager as B, buildRuntimeCommunityFields as Bn, RpcExportCommunityModLogsParamSchema as Bt, RepliesPages as C, verifyChallengeRequest as Cn, n$6 as Cr, parseDecryptedChallengeVerification as Ct, extractCommunityRuntimeFieldsFromParsedPages as D, verifyCommentModeration as Dn, MAX_FILE_SIZE_BYTES_FOR_COMMENT_UPDATE as Dr, parseRpcCommentEventWithPKCErrorIfItFails as Dt, buildPagesRuntimeFields as E, verifyCommentIpfs as En, stringify as Er, parsePKCUserOptionsSchemaWithPKCErrorIfItFails as Et, collectCrosspostAuthorsToResolve as F, getAuthorNameFromRuntime as Fn, RpcCidParamSchema as Ft, decodeRpcChallengeAnswerPubsubMsg as G, decode as Gn, RpcFetchCidResultSchema as Gt, pRetry as H, getCommunityNameFromWire$1 as Hn, RpcExportCommunityParamSchema as Ht, extractCrosspostRuntimeFields as I, getAuthorNameFromWire as In, RpcCommentRepliesPageParamSchema as It, decodeRpcChallengeVerificationPubsubMsg as J, getIpfsKeyFromPrivateKey as Jn, RpcPublishedAnchorRecordResultSchema as Jt, decodeRpcChallengePubsubMsg as K, encode as Kn, RpcPublishAnchorRecordParamSchema as Kt, stripNameResolvedFromCrosspost as L, normalizeCreatePublicationAuthor as Ln, RpcCommunityIdentifierParamSchema as Lt, parseRawPages as M, verifyVote as Mn, require_lodash_merge as Mr, RpcAnchorPublishPreparationResultSchema as Mt, applyNameResolvedCacheToCrosspost as N, buildRuntimeAuthor as Nn, nativeFunctions$1 as Nr, RpcAuthorNameParamSchema as Nt, findCommentInPageInstance as O, verifyCommentPubsubMessage as On, NAME_RESOLVED_FALSE_TTL_MS as Or, parseRpcCommentUpdateEventWithPKCErrorIfItFails as Ot, cloneCrosspostForRuntime as P, cleanWireAuthor as Pn, require_undici as Pr, RpcCancelExportParamSchema as Pt, createSchemaRowParser as Q, BackupAbortError as Qn, RpcUnsubscribeParamSchema as Qt, PKCClientsManager as R, crosspostChainDepthUpTo as Rn, RpcCommunityPageParamSchema as Rt, KeyvBetterSqlite3 as S, verifyChallengeMessage as Sn, n$5 as Sr, parseDecryptedChallengeAnswerWithPKCErrorIfItFails as St, buildPageRuntimeFields as T, verifyCommentEdit as Tn, t$8 as Tr, parseJsonWithPKCErrorIfFails as Tt, pLimit as U, getCommunityPublicKeyFromWire as Un, RpcExportCommunityResultSchema as Ut, InflightResourceTypes as V, getCommunityAddressFromRecord as Vn, RpcExportCommunityModLogsResultSchema as Vt, PKCTypedEmitter as W, normalizeCommunityInputFromCommunity as Wn, RpcFetchCidParamSchema as Wt, coerceSchemaRowJson as X, getPKCAddressFromPublicKeySync as Xn, RpcSubscriptionIdResultSchema as Xt, coerceSchemaRowBoolean as Y, getPKCAddressFromPublicKey as Yn, RpcResolveAuthorNameResultSchema as Yt, collectSchemaRowCoercions as Z, getPublicKeyFromPrivateKey as Zn, RpcSuccessResultSchema as Zt, createAuthorIdentityMatcher as _, signCommentUpdateForChallengeVerification as _n, tryToDeleteCommunitiesThatFailedToBeDeletedBefore as _r, parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails as _t, generatePagesReportingFailedSorts as a, encryptEd25519AesGcm as an, deriveDbPosts as ar, parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails as at, RemoteCommunity as b, signVote as bn, r as br, parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails as bt, resolvePageSortsOrThrow as c, cleanUpBeforePublishing as cn, getDefaultDataPath as cr, parseCommunityAddressWithPKCErrorIfItFails as ct, getChallengeVerification as d, signChallengeRequest as dn, listCommunitiesSync as dr, parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails as dt, SignerWithPublicKeyAddress as en, calculateExpectedSignatureSize as er, parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as et, getCommunityChallengeFromCommunityChallengeSettings as f, signChallengeVerification as fn, monitorCommunitiesDirectory as fr, parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails as ft, authorNameResolveFailureReason as g, signCommentUpdate as gn, setNativeFunctions as gr, parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails as gt, authorIdentityMatcherForRequest as h, signCommentModeration as hn, resolveDbPostsCidRefs as hr, parseCreateCommentOptionsSchemaWithPKCErrorIfItFails as ht, derivePublicPageSorts as i, decryptEd25519AesGcmPublicKeyBuffer as in, deriveCommentIpfsFromCommentTableRow as ir, parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as it, iterateOverPageCidsToFindAllCids as j, verifyCommunityEdit as jn, STORAGE_KEYS as jr, parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails as jt, findCommentInPageInstanceRecursively as k, verifyCommentUpdate as kn, NAME_RESOLVED_TRUE_TTL_MS as kr, parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails as kt, pkcJsPageSorts as l, signChallengeAnswer as ln, getThumbnailPropsOfLink as lr, parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as lt, pkcJsChallenges as m, signCommentEdit as mn, refreshCommunitiesList as mr, parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails as mt, RpcRemoteCommunity as n, createAnchorIpnsRecord as nn, createKuboRpcClient as nr, parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails as nt, loadPageSortsForStartedCommunity as o, encryptEd25519AesGcmPublicKeyBuffer as on, deriveDbReplies as or, parseCommentPubsubMessagePublicationWithPKCErrorIfItFails as ot, loadChallengeFileFromCommunityChallengeSettings as p, signComment as pn, moveCommunityDbToDeletedDirectory as pr, parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails as pt, decodeRpcChallengeRequestPubsubMsg as q, getBufferedPKCAddressFromPublicKey as qn, RpcPublishChallengeAnswersParamSchema as qt, computePageSortsFingerprint as r, decryptEd25519AesGcm as rn, deleteOldCommunityInWindows as rr, parseCommentIpfsSchemaWithPKCErrorIfItFails as rt, lookupPageSortFactories as s, _validateSignatureOfPKCRecord as sn, getDefaultCommunityDbConfig as sr, parseCommentUpdateSchemaWithPKCErrorIfItFails as st, RpcLocalCommunity as t, createSigner as tn, calculateInlineRepliesBudget as tr, parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails as tt, deriveCommunityChallengesOrThrow as u, signChallengeMessage as un, importSignerIntoKuboNode as ur, parseCommunityEditOptionsSchemaWithPKCErrorIfItFails as ut, TrackedInstanceRegistry as v, signCommunity as vn, t$2 as vr, parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails as vt, TIMEFRAMES_TO_SECONDS as w, verifyChallengeVerification as wn, t$7 as wr, parseDecryptedChallengeWithPKCErrorIfItFails as wt, MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS as x, verifyChallengeAnswer as xn, t$5 as xr, parseCreateVoteOptionsSchemaWithPKCErrorIfItFails as xt, LRUCache as y, signCommunityEdit as yn, t$4 as yr, parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails as yt, GenericStateClient as z, effectiveMaxCrosspostDepth as zn, RpcEditCommunityParamSchema as zt };
@@ -5180,6 +5180,7 @@ var messages;
5180
5180
  messages["ERR_CID_IS_INVALID"] = "CID is invalid";
5181
5181
  messages["ERR_DATA_PATH_IS_NOT_DEFINED"] = "pkcOptions.dataPath needs to be defined with native functions";
5182
5182
  messages["ERR_COMMUNITY_OWNER_ATTEMPTED_EDIT_NEW_ADDRESS_THAT_ALREADY_EXISTS"] = "Community owner attempted to edit community.address to a new address that already exists";
5183
+ messages["ERR_COMMUNITY_EDIT_NAME_AND_ADDRESS_MISMATCH"] = "community.edit() received both name and address, and they name different addresses. Pass one of them, or the same value for both";
5183
5184
  messages["ERR_COMMENT_MISSING_IPFS_AND_UPDATE"] = "Comment is missing CommentIpfs and CommentUpdate";
5184
5185
  messages["ERR_COMMENT_MISSING_CID"] = "Comment is missing cid";
5185
5186
  messages["ERR_COMMENT_MISSING_IPFS"] = "Comment is missing CommentIpfs props";
@@ -5435,6 +5436,7 @@ var messages;
5435
5436
  messages["ERR_PUBLICATION_INVALID_COMMUNITY_PUBLIC_KEY"] = "The communityPublicKey field of publication does not match the community's IPNS key";
5436
5437
  messages["ERR_PUBLICATION_SIGNED_TO_MINTER_INSTEAD_OF_ANCHOR"] = "The communityPublicKey field of publication is this delegated community's minter key; publications must be signed to the community's anchor identity";
5437
5438
  messages["ERR_PUBLICATION_INVALID_COMMUNITY_NAME"] = "The communityName field of publication does not match the community's address";
5439
+ messages["ERR_PUBLICATION_MISSING_COMMUNITY_NAME"] = "The publication has no communityName, but the community it is published to has a name; sign it with the community's name";
5438
5440
  messages["ERR_AUTHOR_IS_BANNED"] = "Author is banned";
5439
5441
  messages["ERR_PUBLICATION_HAS_NO_AUTHOR_ADDRESS"] = "Publication has no author.address";
5440
5442
  messages["ERR_COMMUNITY_PUBLICATION_PARENT_HAS_BEEN_REMOVED"] = "The parent of this publication has been removed";
@@ -14802,7 +14804,7 @@ const CommunityEditPublicationPubsubReservedFields = r$2([
14802
14804
  ], t$3(CommunityEditPubsubMessagePublicationSchema.shape));
14803
14805
  //#endregion
14804
14806
  //#region dist/node/generated-version.js
14805
- const version = "0.0.119";
14807
+ const version = "0.0.120";
14806
14808
  //#endregion
14807
14809
  //#region dist/node/version.js
14808
14810
  const protocolVersion = ProtocolVersionSchema.parse("1.0.0");
@@ -1,4 +1,4 @@
1
- import { Ar as PKCError, z as pubsubTopicToDhtKeyCid } from "./util-B-JWgzlN.js";
1
+ import { Ar as PKCError, z as pubsubTopicToDhtKeyCid } from "./util-CXxGmK2P.js";
2
2
  import { ipnsSelector } from "ipns/selector";
3
3
  import { ipnsValidator } from "ipns/validator";
4
4
  import { unmarshalIPNSRecord } from "ipns";
@@ -1,5 +1,5 @@
1
- import { Ar as PKCError, _n as PageSortFileFactorySchema, an as ChallengeFileSchema, in as ChallengeFileFactorySchema } from "./util-B-JWgzlN.js";
2
- import { s as validatePageSortFile } from "./page-sort-scoring-Drqxj8Pi.js";
1
+ import { Ar as PKCError, _n as PageSortFileFactorySchema, an as ChallengeFileSchema, in as ChallengeFileFactorySchema } from "./util-CXxGmK2P.js";
2
+ import { s as validatePageSortFile } from "./page-sort-scoring-B2iu-tyC.js";
3
3
  //#region dist/node/validate-package-factories.js
4
4
  function validateChallengeFileFactory(factory, { name }) {
5
5
  try {
@@ -1,2 +1,2 @@
1
- import { a as getShortCid, c as setNativeFunctions, i as getShortAddress, n as challenges, o as nativeFunctions, r as createAnchorIpnsRecord, s as pageSorts, t as PKC } from "./chunks/node-BHLzTAo9.js";
1
+ import { a as getShortCid, c as setNativeFunctions, i as getShortAddress, n as challenges, o as nativeFunctions, r as createAnchorIpnsRecord, s as pageSorts, t as PKC } from "./chunks/node-CsHuIZmP.js";
2
2
  export { challenges, createAnchorIpnsRecord, PKC as default, getShortAddress, getShortCid, nativeFunctions, pageSorts, setNativeFunctions };
@@ -1,2 +1,2 @@
1
- import { n as validatePageSortFileFactory } from "./chunks/validate-package-factories-BSmEBl_0.js";
1
+ import { n as validatePageSortFileFactory } from "./chunks/validate-package-factories-BpJjVrRb.js";
2
2
  export { validatePageSortFileFactory };
@@ -1,7 +1,7 @@
1
- import { Ar as PKCError, Dt as pTimeout, J as replaceXWithY, Mr as logger_default, S as hideClassPrivateProps, dr as n, pr as t, ut as findStartedCommunity } from "../../chunks/util-B-JWgzlN.js";
2
- import { _ as parseRpcExportCommunityParam, b as parseRpcUnsubscribeParam, d as parseRpcCidParam, f as parseRpcCommentRepliesPageParam, g as parseRpcExportCommunityModLogsParam, h as parseRpcEditCommunityParam, l as parseRpcAuthorNameParam, m as parseRpcCommunityPageParam, p as parseRpcCommunityIdentifierParam, t as PKC, u as parseRpcCancelExportParam, v as parseRpcPublishAnchorRecordParam, y as parseRpcPublishChallengeAnswersParam } from "../../chunks/node-BHLzTAo9.js";
3
- import { $t as require_lib, At as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, E as buildPagesRuntimeFields, H as pRetry, I as extractCrosspostRuntimeFields, St as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, T as buildPageRuntimeFields, Tr as stringify, U as pLimit, _t as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails, et as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, it as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, kt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, lt as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, tt as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ut as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, vr as t$1, vt as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails } from "../../chunks/rpc-local-community-_ooAoNPM.js";
4
- import { t as LocalCommunity } from "../../chunks/local-community-DngOEreY.js";
1
+ import { Ar as PKCError, Dt as pTimeout, J as replaceXWithY, Mr as logger_default, S as hideClassPrivateProps, dr as n, pr as t, ut as findStartedCommunity } from "../../chunks/util-CXxGmK2P.js";
2
+ import { _ as parseRpcExportCommunityParam, b as parseRpcUnsubscribeParam, d as parseRpcCidParam, f as parseRpcCommentRepliesPageParam, g as parseRpcExportCommunityModLogsParam, h as parseRpcEditCommunityParam, l as parseRpcAuthorNameParam, m as parseRpcCommunityPageParam, p as parseRpcCommunityIdentifierParam, t as PKC, u as parseRpcCancelExportParam, v as parseRpcPublishAnchorRecordParam, y as parseRpcPublishChallengeAnswersParam } from "../../chunks/node-CsHuIZmP.js";
3
+ import { $t as require_lib, At as parseVoteChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, E as buildPagesRuntimeFields, Er as stringify, H as pRetry, I as extractCrosspostRuntimeFields, St as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, T as buildPageRuntimeFields, U as pLimit, _t as parseCreateNewLocalCommunityUserOptionsSchemaWithPKCErrorIfItFails, et as parseCommentChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, it as parseCommentModerationChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, kt as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, lt as parseCommunityEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, tt as parseCommentEditChallengeRequestToEncryptSchemaWithPKCErrorIfItFails, ut as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, vt as parseCreatePKCWsServerOptionsSchemaWithPKCErrorIfItFails, yr as t$1 } from "../../chunks/rpc-local-community-DMDs0XGh.js";
4
+ import { t as LocalCommunity } from "../../chunks/local-community-BbJyIuOc.js";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import path from "path";
7
7
  import assert from "assert";
@@ -138,6 +138,7 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
138
138
  this._onSettingsChange = {};
139
139
  this._settingsSenders = /* @__PURE__ */ new Map();
140
140
  this._startedCommunities = {};
141
+ this._addressChangeListeners = /* @__PURE__ */ new WeakMap();
141
142
  this._autoStartOnBoot = false;
142
143
  this._exportCommunityInstances = /* @__PURE__ */ new Map();
143
144
  this._ownsHttpServer = false;
@@ -238,6 +239,13 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
238
239
  const { name, publicKey } = identifier;
239
240
  if (!name && !publicKey) throw new Error("At least one of name or publicKey must be provided");
240
241
  if (name && name in this._startedCommunities) return name;
242
+ if (publicKey) {
243
+ const startedAddress = Object.keys(this._startedCommunities).find((address) => {
244
+ const entry = this._startedCommunities[address];
245
+ return entry !== "pending" && entry.publicKey === publicKey;
246
+ });
247
+ if (startedAddress) return startedAddress;
248
+ }
241
249
  if (name && this.pkc.communities.includes(name)) return name;
242
250
  if (publicKey && publicKey in this._startedCommunities) return publicKey;
243
251
  if (publicKey && this.pkc.communities.includes(publicKey)) return publicKey;
@@ -279,6 +287,31 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
279
287
  if (!db) return;
280
288
  db.prepare("DELETE FROM community_states WHERE address = ?").run(address);
281
289
  }
290
+ _moveCommunityState(oldAddress, newAddress) {
291
+ const db = this._getRpcStateDb();
292
+ if (!db || oldAddress === newAddress) return;
293
+ db.prepare("UPDATE OR REPLACE community_states SET address = @newAddress WHERE address = @oldAddress").run({
294
+ newAddress,
295
+ oldAddress
296
+ });
297
+ }
298
+ _fileStartedCommunityUnderItsAddress(community) {
299
+ if (this._startedCommunities[community.address] === community) return;
300
+ const filedAddress = Object.keys(this._startedCommunities).find((address) => this._startedCommunities[address] === community);
301
+ if (filedAddress === void 0) return;
302
+ this._startedCommunities[community.address] = community;
303
+ delete this._startedCommunities[filedAddress];
304
+ this._moveCommunityState(filedAddress, community.address);
305
+ }
306
+ _followAddressChanges(community) {
307
+ let listener = this._addressChangeListeners.get(community);
308
+ if (!listener) {
309
+ listener = () => this._fileStartedCommunityUnderItsAddress(community);
310
+ this._addressChangeListeners.set(community, listener);
311
+ }
312
+ if (community.listeners("update").includes(listener)) return;
313
+ community.on("update", listener);
314
+ }
282
315
  async _autoStartPreviousCommunities() {
283
316
  if (!this._autoStartOnBoot) return;
284
317
  const autoStartLog = logger_default("pkc-js-rpc:pkc-ws-server:auto-start");
@@ -340,6 +373,8 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
340
373
  wasStarted: true,
341
374
  wasExplicitlyStopped: false
342
375
  });
376
+ this._followAddressChanges(community);
377
+ this._fileStartedCommunityUnderItsAddress(community);
343
378
  return community;
344
379
  } catch (e) {
345
380
  delete this._startedCommunities[address];
@@ -598,6 +633,8 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
598
633
  wasStarted: true,
599
634
  wasExplicitlyStopped: false
600
635
  });
636
+ this._followAddressChanges(community);
637
+ this._fileStartedCommunityUnderItsAddress(community);
601
638
  } catch (e) {
602
639
  const cleanup = this.subscriptionCleanups?.[connectionId]?.[subscriptionId];
603
640
  if (cleanup) await cleanup();
@@ -606,17 +643,21 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
606
643
  }
607
644
  };
608
645
  this._onSettingsChange[connectionId][subscriptionId] = async ({ newPKC }) => {
609
- const current = this._startedCommunities[address];
646
+ const filedAddress = this._findCommunityAddress({
647
+ name,
648
+ publicKey
649
+ }) ?? address;
650
+ const current = this._startedCommunities[filedAddress];
610
651
  if (!current || current === "pending") return;
611
- const community = await this.getStartedCommunity(address);
612
- this._startedCommunities[address] = "pending";
652
+ const community = await this.getStartedCommunity(filedAddress);
653
+ this._startedCommunities[filedAddress] = "pending";
613
654
  try {
614
655
  await community.stop();
615
656
  community._pkc = newPKC;
616
657
  await community.start();
617
- this._startedCommunities[address] = community;
658
+ this._startedCommunities[filedAddress] = community;
618
659
  } catch (error) {
619
- delete this._startedCommunities[address];
660
+ delete this._startedCommunities[filedAddress];
620
661
  throw error;
621
662
  }
622
663
  };
@@ -662,6 +703,8 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
662
703
  for (const [event, listeners] of trackedListeners) for (const listener of listeners) community.removeListener(event, listener);
663
704
  this._trackedCommunityListeners.delete(community);
664
705
  }
706
+ const addressChangeListener = this._addressChangeListeners.get(community);
707
+ if (addressChangeListener) community.removeListener("update", addressChangeListener);
665
708
  }
666
709
  async editCommunity(params) {
667
710
  const rawParam = params[0];
@@ -674,8 +717,9 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
674
717
  publicKey
675
718
  });
676
719
  if (!address) throw new PKCError("ERR_RPC_CLIENT_TRYING_TO_EDIT_REMOTE_COMMUNITY", { communityAddress: name || publicKey });
720
+ const startedCommunity = address in this._startedCommunities ? await this.getStartedCommunity(address) : void 0;
677
721
  let community;
678
- if (this._startedCommunities[address] instanceof LocalCommunity) community = this._startedCommunities[address];
722
+ if (startedCommunity instanceof LocalCommunity) community = startedCommunity;
679
723
  else {
680
724
  community = await pkc.createCommunity({ address });
681
725
  community.once("error", (error) => {
@@ -683,15 +727,8 @@ var PKCWsServer = class extends import_lib.TypedEmitter {
683
727
  });
684
728
  }
685
729
  await community.edit(editCommunityOptions);
686
- if (editCommunityOptions.address && this._startedCommunities[address]) {
687
- this._startedCommunities[editCommunityOptions.address] = this._startedCommunities[address];
688
- delete this._startedCommunities[address];
689
- const db = this._getRpcStateDb();
690
- if (db) db.prepare("UPDATE community_states SET address = @newAddress WHERE address = @oldAddress").run({
691
- newAddress: editCommunityOptions.address,
692
- oldAddress: address
693
- });
694
- }
730
+ if (community.address !== address) if (startedCommunity === community) this._fileStartedCommunityUnderItsAddress(community);
731
+ else this._moveCommunityState(address, community.address);
695
732
  if (typeof community.updatedAt === "number") return community.toJSONInternalRpcAfterFirstUpdate();
696
733
  else return community.toJSONInternalRpcBeforeFirstUpdate();
697
734
  }
@@ -874,13 +874,19 @@ export class CommunityClientsManager extends PKCClientsManager {
874
874
  // non-delegated community (no claim) ipnsName is the identity, unchanged.
875
875
  const identityPublicKey = subRes.community.anchor?.publicKey ?? ipnsName;
876
876
  const anchorIdentityAddress = subRes.community.name || identityPublicKey;
877
- this._pkc._memCaches.communityForPublishing.set(anchorIdentityAddress, {
877
+ const communityForPublishing = {
878
878
  encryption: subRes.community.encryption,
879
879
  pubsubTopic: subRes.community.pubsubTopic,
880
880
  address: anchorIdentityAddress,
881
881
  publicKey: identityPublicKey,
882
882
  name: subRes.community.name
883
- });
883
+ };
884
+ // Under the name and under the key: a publication created with only the key reads the community's
885
+ // current name here to re-sign with it (issue #401), so the key's entry must not keep a record from
886
+ // before the community got its name
887
+ this._pkc._memCaches.communityForPublishing.set(anchorIdentityAddress, communityForPublishing);
888
+ if (anchorIdentityAddress !== identityPublicKey)
889
+ this._pkc._memCaches.communityForPublishing.set(identityPublicKey, communityForPublishing);
884
890
  }
885
891
  return subRes;
886
892
  });