@pkcprotocol/pkc-js 0.0.80 → 0.0.82

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 (173) hide show
  1. package/README.md +3 -1
  2. package/dist/browser/clients/base-client-manager.js +19 -1
  3. package/dist/browser/clients/base-client-manager.js.map +1 -1
  4. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +1 -0
  5. package/dist/browser/clients/rpc-client/schema.d.ts +3 -0
  6. package/dist/browser/community/schema.d.ts +24 -0
  7. package/dist/browser/community/schema.js +6 -1
  8. package/dist/browser/community/schema.js.map +1 -1
  9. package/dist/browser/errors.d.ts +10 -1
  10. package/dist/browser/errors.js +10 -1
  11. package/dist/browser/errors.js.map +1 -1
  12. package/dist/browser/generated-version.d.ts +1 -1
  13. package/dist/browser/generated-version.js +1 -1
  14. package/dist/browser/pages/pages.js +8 -0
  15. package/dist/browser/pages/pages.js.map +1 -1
  16. package/dist/browser/pages/schema.d.ts +4 -0
  17. package/dist/browser/pages/util.d.ts +2 -0
  18. package/dist/browser/pages/util.js +23 -3
  19. package/dist/browser/pages/util.js.map +1 -1
  20. package/dist/browser/pkc/pkc.d.ts +3 -2
  21. package/dist/browser/pkc/pkc.js +37 -24
  22. package/dist/browser/pkc/pkc.js.map +1 -1
  23. package/dist/browser/pkc-error.d.ts +1 -1
  24. package/dist/browser/publications/comment/comment-client-manager.js +22 -4
  25. package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
  26. package/dist/browser/publications/comment/comment.d.ts +2 -1
  27. package/dist/browser/publications/comment/comment.js +29 -6
  28. package/dist/browser/publications/comment/comment.js.map +1 -1
  29. package/dist/browser/publications/comment/crosspost-depth.d.ts +5 -0
  30. package/dist/browser/publications/comment/crosspost-depth.js +75 -0
  31. package/dist/browser/publications/comment/crosspost-depth.js.map +1 -0
  32. package/dist/browser/publications/comment/crosspost-runtime.d.ts +30 -0
  33. package/dist/browser/publications/comment/crosspost-runtime.js +133 -0
  34. package/dist/browser/publications/comment/crosspost-runtime.js.map +1 -0
  35. package/dist/browser/publications/comment/schema.d.ts +20 -2
  36. package/dist/browser/publications/comment/schema.js +21 -10
  37. package/dist/browser/publications/comment/schema.js.map +1 -1
  38. package/dist/browser/publications/comment/types.d.ts +10 -0
  39. package/dist/browser/publications/community-edit/schema.d.ts +4 -0
  40. package/dist/browser/publications/publication.d.ts +4 -0
  41. package/dist/browser/publications/publication.js +80 -5
  42. package/dist/browser/publications/publication.js.map +1 -1
  43. package/dist/browser/pubsub-messages/schema.d.ts +5 -0
  44. package/dist/browser/rpc/src/index.js +14 -2
  45. package/dist/browser/rpc/src/index.js.map +1 -1
  46. package/dist/browser/runtime/browser/setup-kubo-http-routers.d.ts +1 -0
  47. package/dist/browser/runtime/browser/setup-kubo-http-routers.js +4 -0
  48. package/dist/browser/runtime/browser/setup-kubo-http-routers.js.map +1 -0
  49. package/dist/browser/runtime/node/community/db-handler.js +3 -2
  50. package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
  51. package/dist/browser/runtime/node/community/local-community/publication-validation.js +15 -0
  52. package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
  53. package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.d.ts +3 -2
  54. package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js +19 -10
  55. package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
  56. package/dist/browser/runtime/node/community/page-generator.d.ts +2 -0
  57. package/dist/browser/runtime/node/setup-kubo-http-routers.d.ts +2 -0
  58. package/dist/browser/runtime/node/{setup-kubo-address-rewriter-and-http-router.js → setup-kubo-http-routers.js} +54 -112
  59. package/dist/browser/runtime/node/setup-kubo-http-routers.js.map +1 -0
  60. package/dist/browser/schema/schema-util.d.ts +17 -0
  61. package/dist/browser/schema/schema-util.js +49 -5
  62. package/dist/browser/schema/schema-util.js.map +1 -1
  63. package/dist/browser/signer/signatures.d.ts +1 -10
  64. package/dist/browser/signer/signatures.js +83 -0
  65. package/dist/browser/signer/signatures.js.map +1 -1
  66. package/dist/browser/test/test-util.d.ts +6 -0
  67. package/dist/browser/util.d.ts +3 -4
  68. package/dist/browser/util.js +7 -3
  69. package/dist/browser/util.js.map +1 -1
  70. package/dist/browser/version.js +1 -1
  71. package/dist/bundled/bundle-manifest.json +78 -93
  72. package/dist/bundled/chunks/{helia-for-pkc-BsYWQ7qS.js → helia-for-pkc-CQY3-UYD.js} +31 -31
  73. package/dist/bundled/chunks/{local-community-EqWKTLxr.js → local-community-AZAEiiht.js} +1 -1
  74. package/dist/bundled/chunks/{local-community-CHzhypCp.js → local-community-DRm3r1-Y.js} +16 -6
  75. package/dist/bundled/chunks/{node-4qAZNuJG.js → node-B1J8psGZ.js} +380 -2372
  76. package/dist/bundled/chunks/{rpc-local-community-Cog5rZLG.js → rpc-local-community-0XmKyOdO.js} +298 -580
  77. package/dist/bundled/chunks/{schema-Iavj-cRD.js → schema-BUUhufdT.js} +26 -11
  78. package/dist/bundled/chunks/{util-CfSUfLkV.js → util-Cct7-RT3.js} +1 -1
  79. package/dist/bundled/index.js +1 -1
  80. package/dist/bundled/rpc/src/index.js +13 -5
  81. package/dist/node/clients/base-client-manager.js +19 -1
  82. package/dist/node/clients/base-client-manager.js.map +1 -1
  83. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +1 -0
  84. package/dist/node/clients/rpc-client/schema.d.ts +3 -0
  85. package/dist/node/community/schema.d.ts +24 -0
  86. package/dist/node/community/schema.js +6 -1
  87. package/dist/node/community/schema.js.map +1 -1
  88. package/dist/node/errors.d.ts +10 -1
  89. package/dist/node/errors.js +10 -1
  90. package/dist/node/errors.js.map +1 -1
  91. package/dist/node/generated-version.d.ts +1 -1
  92. package/dist/node/generated-version.js +1 -1
  93. package/dist/node/pages/pages.js +8 -0
  94. package/dist/node/pages/pages.js.map +1 -1
  95. package/dist/node/pages/schema.d.ts +4 -0
  96. package/dist/node/pages/util.d.ts +2 -0
  97. package/dist/node/pages/util.js +23 -3
  98. package/dist/node/pages/util.js.map +1 -1
  99. package/dist/node/pkc/pkc.d.ts +3 -2
  100. package/dist/node/pkc/pkc.js +37 -24
  101. package/dist/node/pkc/pkc.js.map +1 -1
  102. package/dist/node/pkc-error.d.ts +1 -1
  103. package/dist/node/publications/comment/comment-client-manager.js +22 -4
  104. package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
  105. package/dist/node/publications/comment/comment.d.ts +2 -1
  106. package/dist/node/publications/comment/comment.js +29 -6
  107. package/dist/node/publications/comment/comment.js.map +1 -1
  108. package/dist/node/publications/comment/crosspost-depth.d.ts +5 -0
  109. package/dist/node/publications/comment/crosspost-depth.js +75 -0
  110. package/dist/node/publications/comment/crosspost-depth.js.map +1 -0
  111. package/dist/node/publications/comment/crosspost-runtime.d.ts +30 -0
  112. package/dist/node/publications/comment/crosspost-runtime.js +133 -0
  113. package/dist/node/publications/comment/crosspost-runtime.js.map +1 -0
  114. package/dist/node/publications/comment/schema.d.ts +20 -2
  115. package/dist/node/publications/comment/schema.js +21 -10
  116. package/dist/node/publications/comment/schema.js.map +1 -1
  117. package/dist/node/publications/comment/types.d.ts +10 -0
  118. package/dist/node/publications/community-edit/schema.d.ts +4 -0
  119. package/dist/node/publications/publication.d.ts +4 -0
  120. package/dist/node/publications/publication.js +80 -5
  121. package/dist/node/publications/publication.js.map +1 -1
  122. package/dist/node/pubsub-messages/schema.d.ts +5 -0
  123. package/dist/node/rpc/src/index.js +14 -2
  124. package/dist/node/rpc/src/index.js.map +1 -1
  125. package/dist/node/runtime/browser/setup-kubo-http-routers.d.ts +1 -0
  126. package/dist/node/runtime/browser/setup-kubo-http-routers.js +4 -0
  127. package/dist/node/runtime/browser/setup-kubo-http-routers.js.map +1 -0
  128. package/dist/node/runtime/node/community/db-handler.js +3 -2
  129. package/dist/node/runtime/node/community/db-handler.js.map +1 -1
  130. package/dist/node/runtime/node/community/local-community/publication-validation.js +15 -0
  131. package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
  132. package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.d.ts +3 -2
  133. package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js +19 -10
  134. package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -1
  135. package/dist/node/runtime/node/community/page-generator.d.ts +2 -0
  136. package/dist/node/runtime/node/setup-kubo-http-routers.d.ts +2 -0
  137. package/dist/node/runtime/node/{setup-kubo-address-rewriter-and-http-router.js → setup-kubo-http-routers.js} +54 -112
  138. package/dist/node/runtime/node/setup-kubo-http-routers.js.map +1 -0
  139. package/dist/node/schema/schema-util.d.ts +17 -0
  140. package/dist/node/schema/schema-util.js +49 -5
  141. package/dist/node/schema/schema-util.js.map +1 -1
  142. package/dist/node/signer/signatures.d.ts +1 -10
  143. package/dist/node/signer/signatures.js +83 -0
  144. package/dist/node/signer/signatures.js.map +1 -1
  145. package/dist/node/test/test-util.d.ts +6 -0
  146. package/dist/node/util.d.ts +3 -4
  147. package/dist/node/util.js +7 -3
  148. package/dist/node/util.js.map +1 -1
  149. package/dist/node/version.js +1 -1
  150. package/package.json +2 -2
  151. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +0 -1
  152. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +0 -4
  153. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
  154. package/dist/browser/runtime/node/address-rewriter-db.d.ts +0 -33
  155. package/dist/browser/runtime/node/address-rewriter-db.js +0 -156
  156. package/dist/browser/runtime/node/address-rewriter-db.js.map +0 -1
  157. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +0 -47
  158. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +0 -534
  159. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +0 -1
  160. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +0 -4
  161. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
  162. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +0 -1
  163. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +0 -4
  164. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
  165. package/dist/node/runtime/node/address-rewriter-db.d.ts +0 -33
  166. package/dist/node/runtime/node/address-rewriter-db.js +0 -156
  167. package/dist/node/runtime/node/address-rewriter-db.js.map +0 -1
  168. package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +0 -47
  169. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +0 -534
  170. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +0 -1
  171. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +0 -4
  172. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +0 -1
  173. package/dist/bundled/chunks/{src-BEjAH2gY.js → src-WLgFbUwZ.js} +1 -1
@@ -1,19 +1,28 @@
1
1
  import Logger from "../../../../logger.js";
2
2
  import { flat, isDeepEqual, unique } from "remeda";
3
3
  import { CID } from "multiformats/cid";
4
- import { normalizeSelfAddrsForProvider } from "../../addresses-rewriter-proxy-server.js";
5
- // How often LocalCommunity polls its own node for browser-dialable address changes.
6
- // Matches the address-rewriter proxy's own 60s refresh so a rotation is noticed within one cycle.
4
+ // How often LocalCommunity polls its own node for browser-dialable address changes. One minute is
5
+ // short enough that a rotated WebRTC certhash or a re-issued AutoTLS name is noticed while the old
6
+ // provider record is still fresh at the routers.
7
7
  export const ADDRESS_REPROVIDE_POLL_INTERVAL_MS = 60 * 1000;
8
+ // `ipfs id` returns self-addresses with a trailing `/p2p/<peerId>` while `swarm addrs`
9
+ // returns the same transports without it, so unioning them yields each address twice plus
10
+ // non-standard `/p2p`-suffixed entries. The `/routing/v1` provider schema carries the peer id
11
+ // in the separate `ID` field and expects transport-only `Addrs`, so strip the trailing
12
+ // `/p2p/<peerId>` and dedupe before comparing or announcing.
13
+ export function normalizeSelfAddrsForProvider(addrs, peerId) {
14
+ const suffix = `/p2p/${peerId}`;
15
+ return unique(addrs.map((addr) => (addr.endsWith(suffix) ? addr.slice(0, -suffix.length) : addr)));
16
+ }
8
17
  // Transports a browser can actually dial. These are exactly the addresses that rotate/expire frequently
9
- // (WebRTC-direct certhash rotation, AutoTLS WSS) and that kubo prunes from HTTP-router announces, so they
10
- // are the ones whose change must trigger a fresh provide. Plain TCP/QUIC changes are irrelevant to browsers.
18
+ // (WebRTC-direct certhash rotation, AutoTLS WSS), so they are the ones whose change must trigger a fresh
19
+ // provide. Plain TCP/QUIC changes are irrelevant to browsers.
11
20
  export function isBrowserDialableAddr(addr) {
12
21
  return addr.includes("/webrtc") || addr.includes("/ws");
13
22
  }
14
- // Fetch the node's current browser-dialable self-addresses, normalized the same way the address-rewriter
15
- // proxy normalizes them before announcing (strip the trailing /p2p/<peerId>, dedupe), then sorted so the
16
- // result can be compared by value across calls.
23
+ // Fetch the node's current browser-dialable self-addresses, normalized the way a provider record carries
24
+ // them (strip the trailing /p2p/<peerId>, dedupe), then sorted so the result can be compared by value
25
+ // across calls.
17
26
  export async function getBrowserDialableSelfAddrs(client) {
18
27
  const idRes = await client.id();
19
28
  const peerId = idRes.id.toString();
@@ -35,8 +44,8 @@ function connectionCriticalCids(community) {
35
44
  }
36
45
  /**
37
46
  * Re-provide the connection-critical CIDs when the node's browser-dialable (WSS/WebRTC) self-addresses
38
- * have changed since the last provide. This pushes the current addresses to the HTTP routers (via the
39
- * address-rewriter proxy) so browsers don't get NoValidAddressesError against stale/dead addresses.
47
+ * have changed since the last provide. This pushes the current addresses to the HTTP routers so browsers
48
+ * don't get NoValidAddressesError against stale/dead addresses.
40
49
  *
41
50
  * The first observation only establishes a baseline (start() already force-provides these CIDs with fresh
42
51
  * addresses via providePubsubTopicRoutingCidsIfNeeded); subsequent changes trigger a re-provide.
@@ -1 +1 @@
1
- {"version":3,"file":"reprovide-on-address-change.js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,MAAM,CAAC,KAAK,UAAU,6BAA6B,CAAC,SAAoC;IACpF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IACI,OAAO,SAAS,CAAC,4BAA4B,KAAK,QAAQ;QAC1D,GAAG,GAAG,SAAS,CAAC,4BAA4B,GAAG,kCAAkC;QAEjF,OAAO;IACX,SAAS,CAAC,4BAA4B,GAAG,GAAG,CAAC;IAC7C,MAAM,4CAA4C,CAAC,SAAS,CAAC,CAAC;AAClE,CAAC"}
1
+ {"version":3,"file":"reprovide-on-address-change.js","sourceRoot":"","sources":["../../../../../../src/runtime/node/community/local-community/reprovide-on-address-change.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAEvC,kGAAkG;AAClG,mGAAmG;AACnG,iDAAiD;AACjD,MAAM,CAAC,MAAM,kCAAkC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5D,uFAAuF;AACvF,0FAA0F;AAC1F,8FAA8F;AAC9F,uFAAuF;AACvF,6DAA6D;AAC7D,MAAM,UAAU,6BAA6B,CAAC,KAAe,EAAE,MAAc;IACzE,MAAM,MAAM,GAAG,QAAQ,MAAM,EAAE,CAAC;IAChC,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvG,CAAC;AAsBD,wGAAwG;AACxG,yGAAyG;AACzG,8DAA8D;AAC9D,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAC9C,O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D,IAAI,CAAC;YACD,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACvE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,aAAa;gBAAE,GAAG,CAAC,KAAK,CAAC,qBAAqB,SAAS,GAAG,EAAE,KAAK,CAAC,CAAC;YAC7F,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,GAAG,CAAC,KAAK,CAAC,iDAAiD,SAAS,oBAAoB,SAAS,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC;QACrH,CAAC;IACL,CAAC;IAED,GAAG,CACC,4CAA4C,SAAS,CAAC,OAAO,0BAA0B,YAAY,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,2BAA2B,EAC1J,EAAE,YAAY,EAAE,OAAO,EAAE,CAC5B,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;AACxF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CAAC,SAAoC;IACpF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IACI,OAAO,SAAS,CAAC,4BAA4B,KAAK,QAAQ;QAC1D,GAAG,GAAG,SAAS,CAAC,4BAA4B,GAAG,kCAAkC;QAEjF,OAAO;IACX,SAAS,CAAC,4BAA4B,GAAG,GAAG,CAAC;IAC7C,MAAM,4CAA4C,CAAC,SAAS,CAAC,CAAC;AAClE,CAAC"}
@@ -78,6 +78,7 @@ export declare class PageGenerator {
78
78
  parentCid?: string | undefined;
79
79
  postCid?: string | undefined;
80
80
  quotedCids?: string[] | undefined;
81
+ crosspost?: import("../../../publications/comment/schema.js").Crosspost | undefined;
81
82
  author?: {
82
83
  [x: string]: unknown;
83
84
  name?: string | undefined;
@@ -269,6 +270,7 @@ export declare class PageGenerator {
269
270
  parentCid?: string | undefined;
270
271
  postCid?: string | undefined;
271
272
  quotedCids?: string[] | undefined;
273
+ crosspost?: import("../../../publications/comment/schema.js").Crosspost | undefined;
272
274
  author?: {
273
275
  [x: string]: unknown;
274
276
  name?: string | undefined;
@@ -0,0 +1,2 @@
1
+ import { PKC } from "../../pkc/pkc.js";
2
+ export declare function setupKuboHttpRouters(pkc: PKC): Promise<void>;
@@ -1,10 +1,7 @@
1
1
  import retry from "retry";
2
- import { AddressesRewriterProxyServer } from "./addresses-rewriter-proxy-server.js";
3
2
  import Logger from "../../logger.js";
4
3
  import { PKCError } from "../../pkc-error.js";
5
4
  import { isDeepEqual } from "remeda";
6
- import tcpPortUsed from "tcp-port-used";
7
- const MAX_TCP_PORT = 65535;
8
5
  function _mergeRouterConfigs(existingConfig, newConfig) {
9
6
  if (!existingConfig?.Routers)
10
7
  return newConfig;
@@ -32,12 +29,12 @@ function _mergeRouterConfigs(existingConfig, newConfig) {
32
29
  Routers: mergedRouters
33
30
  };
34
31
  }
35
- async function _setProvideDhtSweepEnabledOnKuboNode(kuboClient, sweepEnabled) {
32
+ async function _setProvideDhtSweepEnabledOnKuboNode(kuboClient, sweepEnabled, signal) {
36
33
  const log = Logger("pkc-js:pkc:_init:retrySettingHttpRoutersOnIpfsNodes:setProvideDhtSweepEnabledOnIpfsNode");
37
34
  const configKey = "Provide.DHT.SweepEnabled";
38
35
  const url = `${kuboClient._clientOptions.url}/config?arg=${configKey}&arg=${JSON.stringify(sweepEnabled)}&json=true`;
39
36
  try {
40
- await fetch(url, { method: "POST", headers: kuboClient._clientOptions.headers });
37
+ await fetch(url, { method: "POST", headers: kuboClient._clientOptions.headers, signal });
41
38
  }
42
39
  catch (e) {
43
40
  const error = new PKCError("ERR_FAILED_TO_SET_CONFIG_ON_KUBO_NODE", {
@@ -52,12 +49,12 @@ async function _setProvideDhtSweepEnabledOnKuboNode(kuboClient, sweepEnabled) {
52
49
  }
53
50
  log.trace("Succeeded in setting config key", configKey, "on node", kuboClient._clientOptions.url, "to be", sweepEnabled);
54
51
  }
55
- async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue) {
52
+ async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue, signal) {
56
53
  const log = Logger("pkc-js:pkc:_init:retrySettingHttpRoutersOnIpfsNodes:setHttpRouterOptionsOnIpfsNode");
57
54
  const routingKey = "Routing";
58
55
  let routingConfigBeforeChanging;
59
56
  try {
60
- routingConfigBeforeChanging = await kuboClient._client.config.get(routingKey);
57
+ routingConfigBeforeChanging = await kuboClient._client.config.get(routingKey, { signal });
61
58
  }
62
59
  catch (e) {
63
60
  const error = new PKCError("ERR_FAILED_TO_GET_CONFIG_ON_KUBO_NODE", {
@@ -71,7 +68,7 @@ async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue) {
71
68
  const mergedRoutingValue = _mergeRouterConfigs(routingConfigBeforeChanging, routingValue);
72
69
  const url = `${kuboClient._clientOptions.url}/config?arg=${routingKey}&arg=${JSON.stringify(mergedRoutingValue)}&json=true`;
73
70
  try {
74
- await fetch(url, { method: "POST", headers: kuboClient._clientOptions.headers });
71
+ await fetch(url, { method: "POST", headers: kuboClient._clientOptions.headers, signal });
75
72
  }
76
73
  catch (e) {
77
74
  const error = new PKCError("ERR_FAILED_TO_SET_CONFIG_ON_KUBO_NODE", {
@@ -85,7 +82,7 @@ async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue) {
85
82
  throw error;
86
83
  }
87
84
  log.trace("Succeeded in setting config key", routingKey, "on node", kuboClient._clientOptions.url, "to be", mergedRoutingValue);
88
- await _setProvideDhtSweepEnabledOnKuboNode(kuboClient, false);
85
+ await _setProvideDhtSweepEnabledOnKuboNode(kuboClient, false, signal);
89
86
  const endpointsBefore = Object.values(routingConfigBeforeChanging?.Routers || {})
90
87
  .map((router) => router.Parameters?.Endpoint)
91
88
  .filter((endpoint) => endpoint !== undefined);
@@ -96,7 +93,7 @@ async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue) {
96
93
  log("Config on kubo node has been changed. PKC-js will send shutdown command to node", kuboClient._clientOptions.url, "Clients of pkc-js should restart ipfs node");
97
94
  const shutdownUrl = `${kuboClient._clientOptions.url}/shutdown`;
98
95
  try {
99
- await fetch(shutdownUrl, { method: "POST", headers: kuboClient._clientOptions.headers });
96
+ await fetch(shutdownUrl, { method: "POST", headers: kuboClient._clientOptions.headers, signal });
100
97
  }
101
98
  catch (e) {
102
99
  const error = new PKCError("ERR_FAILED_TO_SHUTDOWN_KUBO_NODE", {
@@ -109,108 +106,29 @@ async function _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue) {
109
106
  }
110
107
  }
111
108
  }
112
- async function _getStartedProxyUrl(pkc, httpRouterUrl) {
109
+ // Kubo publishes the provider records to these routers itself. It used to drop the browser-dialable
110
+ // transports (AutoTLS /tls/ws and webrtc-direct) from anything it PUT to a delegated HTTP router,
111
+ // which is why every router URL below used to be a loopback AddressesRewriterProxyServer that
112
+ // rewrote `Addrs` on the way through. Kubo 0.43.0 fixed that (ipfs/kubo#11394, closing the
113
+ // ipfs/kubo#11369 we filed), so Kubo now points straight at the real routers. Do not reintroduce a
114
+ // rewriting proxy: the addrs it could reconstruct (kubo id + swarm addrs) carry no certhash, so a
115
+ // rewritten webrtc-direct/webtransport addr is one no browser can dial.
116
+ export async function setupKuboHttpRouters(pkc) {
113
117
  if (pkc.destroyed)
114
- return undefined;
115
- const mappingKeyName = `httprouter_proxy_${httpRouterUrl}`;
116
- try {
117
- const urlOfProxyOfHttpRouter = await pkc._storage.getItem(mappingKeyName);
118
- if (pkc.destroyed)
119
- return undefined;
120
- if (urlOfProxyOfHttpRouter) {
121
- const proxyHttpUrl = new URL(urlOfProxyOfHttpRouter);
122
- if (await tcpPortUsed.check(Number(proxyHttpUrl.port), "127.0.0.1"))
123
- return urlOfProxyOfHttpRouter;
124
- if (pkc.destroyed)
125
- return undefined;
126
- await pkc._storage.removeItem(mappingKeyName);
127
- }
128
- return undefined;
129
- }
130
- catch (error) {
131
- if (pkc.destroyed && error instanceof Error && error.message.includes("database connection is not open")) {
132
- return undefined;
133
- }
134
- throw error;
135
- }
136
- }
137
- export async function setupKuboAddressesRewriterAndHttpRouters(pkc) {
138
- if (pkc.destroyed) {
139
- return {
140
- destroy: async () => { }
141
- };
142
- }
118
+ return;
143
119
  if (!Array.isArray(pkc.kuboRpcClientsOptions) || pkc.kuboRpcClientsOptions.length <= 0)
144
120
  throw Error("need ipfs http client to be defined");
145
121
  if (!Array.isArray(pkc.httpRoutersOptions) || pkc.httpRoutersOptions.length <= 0)
146
122
  throw Error("Need http router options to defined");
147
- const log = Logger("pkc-js:node:setupKuboAddressesRewriterAndHttpRouters");
148
- // Set up http proxies first to rewrite addresses
149
- const httpRouterProxyUrls = [];
150
- const proxyServers = [];
151
- // Port 19575 looks like IPRTR (IPFS ROUTER). The loop below walks upward from here to the first
152
- // free port, so a busy 19575 is not fatal.
153
- //
154
- // PKC_ADDRESSES_REWRITER_START_PORT moves that base. It exists for tests: the port is process-wide
155
- // and shared by every PKC instance, so two test files that both assume 19575 — one starting a
156
- // proxy on it, one asserting it is free — collide whenever vitest's --parallel scheduling puts
157
- // them in flight together. Each file can now claim its own base instead. Left unset in
158
- // production on purpose: the chosen port is written into Kubo's Routing config, and a changed
159
- // endpoint set bounces the daemon, so the base has to stay stable across restarts.
160
- const parsedStartPortOverride = Number(process.env.PKC_ADDRESSES_REWRITER_START_PORT);
161
- let addressesRewriterStartPort = Number.isInteger(parsedStartPortOverride) && parsedStartPortOverride > 0 && parsedStartPortOverride <= MAX_TCP_PORT
162
- ? parsedStartPortOverride
163
- : 19575;
164
- for (const httpRouter of pkc.httpRoutersOptions) {
165
- if (pkc.destroyed)
166
- break;
167
- const startedProxyUrl = await _getStartedProxyUrl(pkc, httpRouter);
168
- if (startedProxyUrl) {
169
- // Intentionally not tracked in proxyServers: this proxy was started by a previous PKC
170
- // instance in the same process and persisted via storage. We have no server handle to it
171
- // and must not destroy() it on teardown, since another instance may still rely on it. It
172
- // is bounded (one proxy per httpRouter, reusing the same stored URL) and lives until the
173
- // process exits, so this is reuse by design, not a leak.
174
- httpRouterProxyUrls.push(startedProxyUrl);
175
- continue;
176
- }
177
- // launch the proxy server
178
- let port = addressesRewriterStartPort;
179
- const hostname = "127.0.0.1";
180
- // keep increasing port till we find an empty port. Bounded at the top of the TCP range:
181
- // tcpPortUsed.check rejects anything above it with "invalid port", so an unbounded walk would
182
- // surface exhaustion as that opaque error instead of saying what actually went wrong.
183
- while (await tcpPortUsed.check(port, hostname)) {
184
- port++;
185
- if (port > MAX_TCP_PORT)
186
- throw Error(`No free loopback port for the addresses rewriter proxy between ${addressesRewriterStartPort} and ${MAX_TCP_PORT}`);
187
- }
188
- const addressesRewriterProxyServer = new AddressesRewriterProxyServer({
189
- kuboClients: Object.values(pkc.clients.kuboRpcClients).map((kubo) => kubo._client),
190
- port,
191
- hostname,
192
- proxyTargetUrl: httpRouter,
193
- pkc
194
- });
195
- await addressesRewriterProxyServer.listen();
196
- if (pkc.destroyed) {
197
- await addressesRewriterProxyServer.destroy();
198
- break;
199
- }
200
- proxyServers.push(addressesRewriterProxyServer);
201
- // save the proxy urls to use them later
202
- const httpRouterProxyUrl = `http://${hostname}:${port}`;
203
- httpRouterProxyUrls.push(httpRouterProxyUrl);
204
- }
205
- httpRouterProxyUrls.sort(); // make sure it's always the same order
206
- // Set up http routers to use proxies
123
+ const log = Logger("pkc-js:node:setupKuboHttpRouters");
124
+ const httpRouterUrls = [...pkc.httpRoutersOptions].sort(); // make sure it's always the same order
207
125
  const kuboClients = pkc.clients.kuboRpcClients;
208
126
  const parallelRouters = [];
209
127
  const httpRoutersConfig = {
210
128
  HttpRoutersParallel: { Type: "parallel", Parameters: { Routers: parallelRouters } },
211
129
  HttpRouterNotSupported: { Type: "http", Parameters: { Endpoint: "http://kubohttprouternotsupported" } }
212
130
  };
213
- for (const [i, httpRouterUrl] of httpRouterProxyUrls.entries()) {
131
+ for (const [i, httpRouterUrl] of httpRouterUrls.entries()) {
214
132
  const RouterName = `HttpRouter${i + 1}`;
215
133
  httpRoutersConfig[RouterName] = {
216
134
  Type: "http",
@@ -240,28 +158,52 @@ export async function setupKuboAddressesRewriterAndHttpRouters(pkc) {
240
158
  // Cap the backoff: with forever:true and no maxTimeout the exponential delay grows unbounded
241
159
  // (hours between attempts after enough failures), which would stall router setup indefinitely.
242
160
  const settingOptionRetryOption = retry.operation({ forever: true, factor: 2, maxTimeout: 60 * 1000 });
161
+ // destroy() aborts this signal before it awaits the setup promise, so it doubles as the cancel
162
+ // signal for both the in-flight requests below and the retry schedule.
163
+ const destroySignal = pkc._getDestroyAbortSignal();
164
+ let removeDestroyListener;
243
165
  const setHttpRouterOnAllNodes = new Promise((resolve) => {
244
- settingOptionRetryOption.attempt(async (curAttempt) => {
166
+ // The `pkc.destroyed` check below only runs at the top of an attempt, so a destroy landing
167
+ // inside a backoff window would otherwise make destroy() wait out the remaining delay (up to
168
+ // maxTimeout). stop() drops the scheduled attempt (it clears the timer and empties both the
169
+ // pending and cached timeouts, so a racing retry() schedules nothing) and resolving lets
170
+ // destroy() move on immediately.
171
+ const onDestroy = () => {
172
+ settingOptionRetryOption.stop();
173
+ resolve();
174
+ };
175
+ if (destroySignal.aborted) {
176
+ onDestroy();
177
+ return;
178
+ }
179
+ destroySignal.addEventListener("abort", onDestroy, { once: true });
180
+ removeDestroyListener = () => destroySignal.removeEventListener("abort", onDestroy);
181
+ settingOptionRetryOption.attempt(async () => {
182
+ // A destroyed PKC has nothing left to configure, and `forever: true` would otherwise keep
183
+ // retrying against a torn-down instance for the life of the process.
184
+ if (pkc.destroyed) {
185
+ resolve();
186
+ return;
187
+ }
245
188
  for (const kuboClient of Object.values(kuboClients)) {
246
189
  try {
247
- await _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue);
190
+ await _setHttpRouterOptionsOnKuboNode(kuboClient, routingValue, destroySignal);
248
191
  }
249
192
  catch (e) {
250
193
  settingOptionRetryOption.retry(e);
251
194
  return;
252
195
  }
253
196
  }
254
- resolve(1);
197
+ resolve();
255
198
  });
256
199
  });
257
200
  await setHttpRouterOnAllNodes;
201
+ // Detach before returning: the destroy signal outlives this call, and leaving the listener on it
202
+ // would accumulate one per setup for the life of the instance.
203
+ removeDestroyListener?.();
258
204
  settingOptionRetryOption.stop();
259
- return {
260
- destroy: async () => {
261
- for (const proxyServer of proxyServers) {
262
- await proxyServer.destroy();
263
- }
264
- }
265
- };
205
+ if (pkc.destroyed)
206
+ return;
207
+ log.trace("Set http router config on all kubo nodes", Object.keys(kuboClients), "to", httpRouterUrls);
266
208
  }
267
- //# sourceMappingURL=setup-kubo-address-rewriter-and-http-router.js.map
209
+ //# sourceMappingURL=setup-kubo-http-routers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-kubo-http-routers.js","sourceRoot":"","sources":["../../../../src/runtime/node/setup-kubo-http-routers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAgBrC,SAAS,mBAAmB,CAAC,cAA6C,EAAE,SAA4B;IACpG,IAAI,CAAC,cAAc,EAAE,OAAO;QAAE,OAAO,SAAS,CAAC;IAE/C,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAA2D,CAAC;IACrG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE;QACpE,IAAI,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC;YAC9B,yBAAyB,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EA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C,EAAE,CAAC;gBAClD,IAAI,CAAC;oBACD,MAAM,+BAA+B,CAAC,UAAU,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;gBACnF,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,wBAAwB,CAAC,KAAK,CAAQ,CAAC,CAAC,CAAC;oBACzC,OAAO;gBACX,CAAC;YACL,CAAC;YACD,OAAO,EAAE,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,uBAAuB,CAAC;IAC9B,iGAAiG;IACjG,+DAA+D;IAC/D,qBAAqB,EAAE,EAAE,CAAC;IAC1B,wBAAwB,CAAC,IAAI,EAAE,CAAC;IAChC,IAAI,GAAG,CAAC,SAAS;QAAE,OAAO;IAC1B,GAAG,CAAC,KAAK,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;AAC1G,CAAC"}
@@ -58,6 +58,7 @@ export declare function parseModQueuePageIpfsSchemaWithPKCErrorIfItFails(modQueu
58
58
  parentCid?: string | undefined;
59
59
  postCid?: string | undefined;
60
60
  quotedCids?: string[] | undefined;
61
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
61
62
  author?: {
62
63
  [x: string]: unknown;
63
64
  name?: string | undefined;
@@ -230,6 +231,7 @@ export declare function parseRpcRemoteCommunityUpdateEventWithPKCErrorIfItFails(
230
231
  parentCid?: string | undefined;
231
232
  postCid?: string | undefined;
232
233
  quotedCids?: string[] | undefined;
234
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
233
235
  author?: {
234
236
  [x: string]: unknown;
235
237
  name?: string | undefined;
@@ -417,6 +419,7 @@ export declare function parseRpcRemoteCommunityUpdateEventWithPKCErrorIfItFails(
417
419
  noReplyLinks?: boolean | undefined;
418
420
  noPolls?: boolean | undefined;
419
421
  noCrossposts?: boolean | undefined;
422
+ maxCrosspostDepth?: number | undefined;
420
423
  noNestedReplies?: boolean | undefined;
421
424
  safeForWork?: boolean | undefined;
422
425
  authorFlairs?: boolean | undefined;
@@ -497,6 +500,7 @@ export declare function parseCommunityEditPubsubMessagePublicationSchemaWithPKCE
497
500
  noReplyLinks?: boolean | undefined;
498
501
  noPolls?: boolean | undefined;
499
502
  noCrossposts?: boolean | undefined;
503
+ maxCrosspostDepth?: number | undefined;
500
504
  noNestedReplies?: boolean | undefined;
501
505
  safeForWork?: boolean | undefined;
502
506
  authorFlairs?: boolean | undefined;
@@ -644,6 +648,7 @@ export declare function parseCreateCommunityEditPublicationOptionsSchemaWithPKCE
644
648
  noReplyLinks?: boolean | undefined;
645
649
  noPolls?: boolean | undefined;
646
650
  noCrossposts?: boolean | undefined;
651
+ maxCrosspostDepth?: number | undefined;
647
652
  noNestedReplies?: boolean | undefined;
648
653
  safeForWork?: boolean | undefined;
649
654
  authorFlairs?: boolean | undefined;
@@ -1232,6 +1237,7 @@ export declare function parseCreateCommunityFunctionArgumentsSchemaWithPKCErrorI
1232
1237
  parentCid?: string | undefined;
1233
1238
  postCid?: string | undefined;
1234
1239
  quotedCids?: string[] | undefined;
1240
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
1235
1241
  author?: {
1236
1242
  [x: string]: unknown;
1237
1243
  name?: string | undefined;
@@ -1419,6 +1425,7 @@ export declare function parseCreateCommunityFunctionArgumentsSchemaWithPKCErrorI
1419
1425
  noReplyLinks?: boolean | undefined;
1420
1426
  noPolls?: boolean | undefined;
1421
1427
  noCrossposts?: boolean | undefined;
1428
+ maxCrosspostDepth?: number | undefined;
1422
1429
  noNestedReplies?: boolean | undefined;
1423
1430
  safeForWork?: boolean | undefined;
1424
1431
  authorFlairs?: boolean | undefined;
@@ -1484,6 +1491,7 @@ export declare function parseCreateCommunityFunctionArgumentsSchemaWithPKCErrorI
1484
1491
  noReplyLinks?: boolean | undefined;
1485
1492
  noPolls?: boolean | undefined;
1486
1493
  noCrossposts?: boolean | undefined;
1494
+ maxCrosspostDepth?: number | undefined;
1487
1495
  noNestedReplies?: boolean | undefined;
1488
1496
  safeForWork?: boolean | undefined;
1489
1497
  authorFlairs?: boolean | undefined;
@@ -1654,6 +1662,7 @@ export declare function parseCreateCommunityFunctionArgumentsSchemaWithPKCErrorI
1654
1662
  noReplyLinks?: boolean | undefined;
1655
1663
  noPolls?: boolean | undefined;
1656
1664
  noCrossposts?: boolean | undefined;
1665
+ maxCrosspostDepth?: number | undefined;
1657
1666
  noNestedReplies?: boolean | undefined;
1658
1667
  safeForWork?: boolean | undefined;
1659
1668
  authorFlairs?: boolean | undefined;
@@ -1731,6 +1740,7 @@ export declare function parseCreateCommunityFunctionArgumentsSchemaWithPKCErrorI
1731
1740
  parentCid?: string | undefined;
1732
1741
  postCid?: string | undefined;
1733
1742
  quotedCids?: string[] | undefined;
1743
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
1734
1744
  author?: {
1735
1745
  [x: string]: unknown;
1736
1746
  name?: string | undefined;
@@ -1982,6 +1992,7 @@ export declare function parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErro
1982
1992
  parentCid?: string | undefined;
1983
1993
  postCid?: string | undefined;
1984
1994
  quotedCids?: string[] | undefined;
1995
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
1985
1996
  author?: {
1986
1997
  [x: string]: unknown;
1987
1998
  name?: string | undefined;
@@ -2169,6 +2180,7 @@ export declare function parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErro
2169
2180
  noReplyLinks?: boolean | undefined;
2170
2181
  noPolls?: boolean | undefined;
2171
2182
  noCrossposts?: boolean | undefined;
2183
+ maxCrosspostDepth?: number | undefined;
2172
2184
  noNestedReplies?: boolean | undefined;
2173
2185
  safeForWork?: boolean | undefined;
2174
2186
  authorFlairs?: boolean | undefined;
@@ -2234,6 +2246,7 @@ export declare function parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErro
2234
2246
  noReplyLinks?: boolean | undefined;
2235
2247
  noPolls?: boolean | undefined;
2236
2248
  noCrossposts?: boolean | undefined;
2249
+ maxCrosspostDepth?: number | undefined;
2237
2250
  noNestedReplies?: boolean | undefined;
2238
2251
  safeForWork?: boolean | undefined;
2239
2252
  authorFlairs?: boolean | undefined;
@@ -2404,6 +2417,7 @@ export declare function parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErro
2404
2417
  noReplyLinks?: boolean | undefined;
2405
2418
  noPolls?: boolean | undefined;
2406
2419
  noCrossposts?: boolean | undefined;
2420
+ maxCrosspostDepth?: number | undefined;
2407
2421
  noNestedReplies?: boolean | undefined;
2408
2422
  safeForWork?: boolean | undefined;
2409
2423
  authorFlairs?: boolean | undefined;
@@ -2481,6 +2495,7 @@ export declare function parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErro
2481
2495
  parentCid?: string | undefined;
2482
2496
  postCid?: string | undefined;
2483
2497
  quotedCids?: string[] | undefined;
2498
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
2484
2499
  author?: {
2485
2500
  [x: string]: unknown;
2486
2501
  name?: string | undefined;
@@ -2703,6 +2718,7 @@ export declare function parseCommentPubsubMessagePublicationWithPKCErrorIfItFail
2703
2718
  parentCid?: string | undefined;
2704
2719
  postCid?: string | undefined;
2705
2720
  quotedCids?: string[] | undefined;
2721
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
2706
2722
  };
2707
2723
  export declare function parseCreateCommentOptionsSchemaWithPKCErrorIfItFails(args: z.infer<typeof CreateCommentOptionsSchema>): {
2708
2724
  signer: {
@@ -2727,6 +2743,7 @@ export declare function parseCreateCommentOptionsSchemaWithPKCErrorIfItFails(arg
2727
2743
  parentCid?: string | undefined;
2728
2744
  postCid?: string | undefined;
2729
2745
  quotedCids?: string[] | undefined;
2746
+ crosspost?: import("../publications/comment/schema.js").Crosspost | undefined;
2730
2747
  author?: {
2731
2748
  [x: string]: unknown;
2732
2749
  name?: string | undefined;
@@ -1,6 +1,7 @@
1
1
  import { ModQueuePageIpfsSchema, PageIpfsSchema } from "../pages/schema.js";
2
2
  import { PKCError } from "../pkc-error.js";
3
3
  import { CommentChallengeRequestToEncryptSchema, CommentIpfsSchema, CommentPubsubMessageWithFlexibleAuthorRefinementSchema, CommentUpdateSchema, CreateCommentOptionsWithRefinementSchema } from "../publications/comment/schema.js";
4
+ import { crosspostChainDepthUpTo, deepestCrosspostChainInCommentUpdateUpTo, deepestCrosspostChainInPageUpTo, MAX_CROSSPOST_DEPTH } from "../publications/comment/crosspost-depth.js";
4
5
  import { DecryptedChallengeAnswerSchema, DecryptedChallengeSchema, DecryptedChallengeVerificationSchema } from "../pubsub-messages/schema.js";
5
6
  import { CreateNewLocalCommunityUserOptionsSchema, CreateRemoteCommunityFunctionArgumentSchema, CreateRpcCommunityFunctionArgumentSchema, CreateCommunityFunctionArgumentsSchema, RpcRemoteCommunityUpdateEventResultSchema, CommunityEditOptionsSchema, CommunityIpfsSchema } from "../community/schema.js";
6
7
  import { CidStringSchema, CommunityAddressSchema } from "./schema.js";
@@ -11,6 +12,31 @@ import { CreateVoteUserOptionsWithRefinementSchema, VoteChallengeRequestToEncryp
11
12
  import { CommentEditChallengeRequestToEncryptSchema, CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, CreateCommentEditOptionsWithRefinementSchema } from "../publications/comment-edit/schema.js";
12
13
  import { PKCUserOptionsSchema } from "../schema.js";
13
14
  import { CreateCommunityEditPublicationOptionsWithRefinementSchema, CommunityEditPublicationChallengeRequestToEncryptSchema, CommunityEditPubsubMessagePublicationSchema } from "../publications/community-edit/schema.js";
15
+ // A crosspost chain must be rejected *before* the record reaches a recursive zod parse, not after.
16
+ // At roughly 1000 levels the parse overflows the stack and throws a RangeError, which safeParse does
17
+ // not convert into a ZodError, so a check placed after it would never run and the RangeError would
18
+ // escape as itself. The walk below adds no stack frame per level and stops at the cap. Issue #250.
19
+ function _throwIfCrosspostChainExceedsMaxDepth(record, details) {
20
+ if (crosspostChainDepthUpTo(record) > MAX_CROSSPOST_DEPTH)
21
+ throw new PKCError("ERR_CROSSPOST_CHAIN_EXCEEDS_MAX_DEPTH", { ...details, maxCrosspostDepth: MAX_CROSSPOST_DEPTH });
22
+ }
23
+ function _throwIfPageCrosspostChainsExceedMaxDepth(pageJson, details) {
24
+ if (deepestCrosspostChainInPageUpTo(pageJson) > MAX_CROSSPOST_DEPTH)
25
+ throw new PKCError("ERR_CROSSPOST_CHAIN_EXCEEDS_MAX_DEPTH", { ...details, maxCrosspostDepth: MAX_CROSSPOST_DEPTH });
26
+ }
27
+ // safeParse turns a ZodError into a PKCError, but zod's parse is itself recursive, and a record
28
+ // nested deeply enough makes it throw a RangeError instead — which escapes safeParse as itself.
29
+ // The depth guards above close the crosspost route into that, but reply pages nest too, so the
30
+ // helpers below report any non-Zod throw as the schema error they already document rather than
31
+ // letting it propagate raw out of getComment, Comment.update and page parsing. Issue #250.
32
+ function _safeParseWithoutLettingNonZodThrowsEscape(schema, json, code, details) {
33
+ try {
34
+ return schema.safeParse(json);
35
+ }
36
+ catch (e) {
37
+ throw new PKCError(code, { ...details, error: e });
38
+ }
39
+ }
14
40
  export function parseJsonWithPKCErrorIfFails(x) {
15
41
  try {
16
42
  return JSON.parse(x);
@@ -31,28 +57,39 @@ export function parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails(communi
31
57
  return communityIpfs;
32
58
  }
33
59
  export function parseCommentIpfsSchemaWithPKCErrorIfItFails(commentIpfsJson) {
34
- const parseRes = CommentIpfsSchema.loose().safeParse(commentIpfsJson);
60
+ _throwIfCrosspostChainExceedsMaxDepth(commentIpfsJson, { commentIpfsJson });
61
+ const parseRes = _safeParseWithoutLettingNonZodThrowsEscape(CommentIpfsSchema.loose(), commentIpfsJson, "ERR_INVALID_COMMENT_IPFS_SCHEMA", {
62
+ commentIpfsJson
63
+ });
35
64
  if (!parseRes.success)
36
65
  throw new PKCError("ERR_INVALID_COMMENT_IPFS_SCHEMA", { zodError: parseRes.error, commentIpfsJson });
37
66
  else
38
67
  return commentIpfsJson;
39
68
  }
40
69
  export function parseCommentUpdateSchemaWithPKCErrorIfItFails(commentUpdateJson) {
41
- const parseRes = CommentUpdateSchema.loose().safeParse(commentUpdateJson);
70
+ // A CommentUpdate carries reply pages, so a chain can arrive nested inside one rather than on
71
+ // the comment itself, under the same 1MB fetch cap.
72
+ if (deepestCrosspostChainInCommentUpdateUpTo(commentUpdateJson) > MAX_CROSSPOST_DEPTH)
73
+ throw new PKCError("ERR_CROSSPOST_CHAIN_EXCEEDS_MAX_DEPTH", { commentUpdateJson, maxCrosspostDepth: MAX_CROSSPOST_DEPTH });
74
+ const parseRes = _safeParseWithoutLettingNonZodThrowsEscape(CommentUpdateSchema.loose(), commentUpdateJson, "ERR_INVALID_COMMENT_UPDATE_SCHEMA", { commentUpdateJson });
42
75
  if (!parseRes.success)
43
76
  throw new PKCError("ERR_INVALID_COMMENT_UPDATE_SCHEMA", { zodError: parseRes.error, commentUpdateJson });
44
77
  else
45
78
  return commentUpdateJson;
46
79
  }
47
80
  export function parsePageIpfsSchemaWithPKCErrorIfItFails(pageIpfsJson) {
48
- const parseRes = PageIpfsSchema.safeParse(pageIpfsJson);
81
+ _throwIfPageCrosspostChainsExceedMaxDepth(pageIpfsJson, { pageIpfsJson });
82
+ const parseRes = _safeParseWithoutLettingNonZodThrowsEscape(PageIpfsSchema, pageIpfsJson, "ERR_INVALID_PAGE_IPFS_SCHEMA", {
83
+ pageIpfsJson
84
+ });
49
85
  if (!parseRes.success)
50
86
  throw new PKCError("ERR_INVALID_PAGE_IPFS_SCHEMA", { zodError: parseRes.error, pageIpfsJson });
51
87
  else
52
88
  return pageIpfsJson;
53
89
  }
54
90
  export function parseModQueuePageIpfsSchemaWithPKCErrorIfItFails(modQueuePageIpfsJson) {
55
- const parseRes = ModQueuePageIpfsSchema.safeParse(modQueuePageIpfsJson);
91
+ _throwIfPageCrosspostChainsExceedMaxDepth(modQueuePageIpfsJson, { modQueuePageIpfsJson });
92
+ const parseRes = _safeParseWithoutLettingNonZodThrowsEscape(ModQueuePageIpfsSchema, modQueuePageIpfsJson, "ERR_INVALID_MODQUEUE_PAGE_IPFS_SCHEMA", { modQueuePageIpfsJson });
56
93
  if (!parseRes.success)
57
94
  throw new PKCError("ERR_INVALID_MODQUEUE_PAGE_IPFS_SCHEMA", { zodError: parseRes.error, modQueuePageIpfsJson });
58
95
  else
@@ -107,6 +144,9 @@ export function parseRpcCommentUpdateEventWithPKCErrorIfItFails(updateResult) {
107
144
  return updateResult;
108
145
  }
109
146
  export function parseRpcCommentEventWithPKCErrorIfItFails(updateResult) {
147
+ // The RPC server has already refused an over-deep chain on the way in, so this is defense in
148
+ // depth rather than the primary gate — but the client is the one that would blow its stack.
149
+ _throwIfCrosspostChainExceedsMaxDepth(updateResult?.comment, { updateResult });
110
150
  const parseRes = RpcCommentEventResultSchema.safeParse(updateResult);
111
151
  if (!parseRes.success)
112
152
  throw new PKCError("ERR_INVALID_RPC_COMMENT_SCHEMA", {
@@ -346,7 +386,8 @@ export function parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFai
346
386
  return args;
347
387
  }
348
388
  export function parseCommentPubsubMessagePublicationWithPKCErrorIfItFails(args) {
349
- const parseRes = CommentPubsubMessageWithFlexibleAuthorRefinementSchema.safeParse(args);
389
+ _throwIfCrosspostChainExceedsMaxDepth(args, { args, type: "CommentPubsubMessagePublication" });
390
+ const parseRes = _safeParseWithoutLettingNonZodThrowsEscape(CommentPubsubMessageWithFlexibleAuthorRefinementSchema, args, "ERR_INVALID_CREATE_COMMENT_ARGS_SCHEMA", { args, type: "CommentPubsubMessagePublication" });
350
391
  if (!parseRes.success)
351
392
  throw new PKCError("ERR_INVALID_CREATE_COMMENT_ARGS_SCHEMA", {
352
393
  zodError: parseRes.error,
@@ -357,6 +398,9 @@ export function parseCommentPubsubMessagePublicationWithPKCErrorIfItFails(args)
357
398
  return args;
358
399
  }
359
400
  export function parseCreateCommentOptionsSchemaWithPKCErrorIfItFails(args) {
401
+ // On the publish side too, so an author building a chain too deep for any client to load finds
402
+ // out locally instead of after burning a challenge.
403
+ _throwIfCrosspostChainExceedsMaxDepth(args, { args, type: "CreateCommentOptions" });
360
404
  const parseRes = CreateCommentOptionsWithRefinementSchema.safeParse(args);
361
405
  if (!parseRes.success)
362
406
  throw new PKCError("ERR_INVALID_CREATE_COMMENT_ARGS_SCHEMA", {