@bitsocial/bitsocial-react-hooks 0.2.2 → 0.2.3

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 (117) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +2 -0
  3. package/dist/hooks/accounts/accounts.d.ts.map +1 -1
  4. package/dist/hooks/accounts/accounts.js +35 -10
  5. package/dist/hooks/accounts/accounts.js.map +1 -1
  6. package/dist/hooks/actions/actions.d.ts.map +1 -1
  7. package/dist/hooks/actions/actions.js +166 -93
  8. package/dist/hooks/actions/actions.js.map +1 -1
  9. package/dist/hooks/authors/author-avatars.d.ts +2 -2
  10. package/dist/hooks/authors/author-avatars.d.ts.map +1 -1
  11. package/dist/hooks/authors/author-avatars.js +48 -20
  12. package/dist/hooks/authors/author-avatars.js.map +1 -1
  13. package/dist/hooks/authors/authors.d.ts.map +1 -1
  14. package/dist/hooks/authors/authors.js +68 -22
  15. package/dist/hooks/authors/authors.js.map +1 -1
  16. package/dist/hooks/comments.d.ts.map +1 -1
  17. package/dist/hooks/comments.js +54 -3
  18. package/dist/hooks/comments.js.map +1 -1
  19. package/dist/hooks/communities.d.ts.map +1 -1
  20. package/dist/hooks/communities.js +41 -12
  21. package/dist/hooks/communities.js.map +1 -1
  22. package/dist/hooks/feeds/feeds.d.ts.map +1 -1
  23. package/dist/hooks/feeds/feeds.js +47 -11
  24. package/dist/hooks/feeds/feeds.js.map +1 -1
  25. package/dist/hooks/pkc-rpc.d.ts.map +1 -1
  26. package/dist/hooks/pkc-rpc.js +33 -20
  27. package/dist/hooks/pkc-rpc.js.map +1 -1
  28. package/dist/hooks/replies.d.ts.map +1 -1
  29. package/dist/hooks/replies.js +30 -4
  30. package/dist/hooks/replies.js.map +1 -1
  31. package/dist/index.d.ts +6 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +4 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/lib/debug-utils.d.ts +4 -4
  36. package/dist/lib/debug-utils.d.ts.map +1 -1
  37. package/dist/lib/debug-utils.js +56 -11
  38. package/dist/lib/debug-utils.js.map +1 -1
  39. package/dist/lib/localforage-lru/localforage-lru.d.ts +1 -0
  40. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -1
  41. package/dist/lib/localforage-lru/localforage-lru.js +48 -10
  42. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -1
  43. package/dist/lib/page-sorts.d.ts +6 -0
  44. package/dist/lib/page-sorts.d.ts.map +1 -1
  45. package/dist/lib/page-sorts.js +45 -9
  46. package/dist/lib/page-sorts.js.map +1 -1
  47. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -1
  48. package/dist/lib/pkc-js/pkc-js-mock-content.js +5 -1
  49. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
  50. package/dist/lib/utils/utils.d.ts.map +1 -1
  51. package/dist/lib/utils/utils.js +24 -16
  52. package/dist/lib/utils/utils.js.map +1 -1
  53. package/dist/lib/validator.d.ts +1 -1
  54. package/dist/lib/validator.d.ts.map +1 -1
  55. package/dist/lib/validator.js +7 -1
  56. package/dist/lib/validator.js.map +1 -1
  57. package/dist/stores/accounts/account-generator.d.ts +1 -0
  58. package/dist/stores/accounts/account-generator.d.ts.map +1 -1
  59. package/dist/stores/accounts/account-generator.js +12 -4
  60. package/dist/stores/accounts/account-generator.js.map +1 -1
  61. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -1
  62. package/dist/stores/accounts/accounts-actions-internal.js +24 -6
  63. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -1
  64. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
  65. package/dist/stores/accounts/accounts-actions.js +339 -98
  66. package/dist/stores/accounts/accounts-actions.js.map +1 -1
  67. package/dist/stores/accounts/accounts-database.d.ts +1 -0
  68. package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
  69. package/dist/stores/accounts/accounts-database.js +82 -15
  70. package/dist/stores/accounts/accounts-database.js.map +1 -1
  71. package/dist/stores/accounts/accounts-store.d.ts +1 -1
  72. package/dist/stores/accounts/accounts-store.d.ts.map +1 -1
  73. package/dist/stores/accounts/accounts-store.js +1 -1
  74. package/dist/stores/accounts/accounts-store.js.map +1 -1
  75. package/dist/stores/accounts/utils.d.ts +5 -1
  76. package/dist/stores/accounts/utils.d.ts.map +1 -1
  77. package/dist/stores/accounts/utils.js +58 -0
  78. package/dist/stores/accounts/utils.js.map +1 -1
  79. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -1
  80. package/dist/stores/authors-comments/authors-comments-store.js +39 -12
  81. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -1
  82. package/dist/stores/comments/comments-store.d.ts +2 -0
  83. package/dist/stores/comments/comments-store.d.ts.map +1 -1
  84. package/dist/stores/comments/comments-store.js +170 -21
  85. package/dist/stores/comments/comments-store.js.map +1 -1
  86. package/dist/stores/communities/communities-store.d.ts.map +1 -1
  87. package/dist/stores/communities/communities-store.js +27 -7
  88. package/dist/stores/communities/communities-store.js.map +1 -1
  89. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -1
  90. package/dist/stores/communities-pages/communities-pages-store.js +60 -8
  91. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -1
  92. package/dist/stores/feeds/feed-sorter.d.ts +5 -2
  93. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -1
  94. package/dist/stores/feeds/feed-sorter.js +15 -4
  95. package/dist/stores/feeds/feed-sorter.js.map +1 -1
  96. package/dist/stores/feeds/feeds-store.d.ts +3 -0
  97. package/dist/stores/feeds/feeds-store.d.ts.map +1 -1
  98. package/dist/stores/feeds/feeds-store.js +36 -26
  99. package/dist/stores/feeds/feeds-store.js.map +1 -1
  100. package/dist/stores/feeds/utils.d.ts +16 -0
  101. package/dist/stores/feeds/utils.d.ts.map +1 -1
  102. package/dist/stores/feeds/utils.js +82 -26
  103. package/dist/stores/feeds/utils.js.map +1 -1
  104. package/dist/stores/replies/replies-store.d.ts.map +1 -1
  105. package/dist/stores/replies/replies-store.js +32 -6
  106. package/dist/stores/replies/replies-store.js.map +1 -1
  107. package/dist/stores/replies/utils.d.ts +3 -2
  108. package/dist/stores/replies/utils.d.ts.map +1 -1
  109. package/dist/stores/replies/utils.js +38 -5
  110. package/dist/stores/replies/utils.js.map +1 -1
  111. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -1
  112. package/dist/stores/replies-pages/replies-pages-store.js +68 -13
  113. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -1
  114. package/dist/types.d.ts +11 -2
  115. package/dist/types.d.ts.map +1 -1
  116. package/dist/types.js.map +1 -1
  117. package/package.json +2 -2
@@ -273,11 +273,16 @@ export const commentIsValid = (comment_1, ...args_1) => __awaiter(void 0, [comme
273
273
  console.log(`community '${comment.communityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`);
274
274
  return false;
275
275
  }
276
+ // without a pkc client, e.g. for a feed whose account was deleted, the comment can't be validated,
277
+ // which says nothing about its community, so don't block it
278
+ if (typeof (pkc === null || pkc === void 0 ? void 0 : pkc.validateComment) !== "function") {
279
+ return false;
280
+ }
276
281
  try {
277
282
  yield pkc.validateComment(comment, { validateReplies });
278
283
  }
279
284
  catch (e) {
280
- if (blockCommunity) {
285
+ if (blockCommunity && comment.communityAddress) {
281
286
  communitiesWithInvalidComments[comment.communityAddress] = true;
282
287
  }
283
288
  console.log("invalid comment", { comment, error: e });
@@ -322,19 +327,10 @@ const repliesAreValid = (comment_1, ...args_1) => __awaiter(void 0, [comment_1,
322
327
  return false;
323
328
  }
324
329
  }
325
- // signature verification
326
- try {
327
- const promises = normalizedReplies.map((reply) => commentIsValid(reply, { validateReplies: false, blockCommunity: true }, pkc));
328
- yield Promise.all(promises);
329
- }
330
- catch (e) {
331
- if (blockCommunity && commentCommunityAddress) {
332
- communitiesWithInvalidComments[commentCommunityAddress] = true;
333
- }
334
- console.log("invalid comment", { comment, error: e });
335
- return false;
336
- }
337
- return true;
330
+ // signature verification, commentIsValid returns false instead of throwing, and blocks the
331
+ // community of an invalid reply itself
332
+ const repliesValidity = yield Promise.all(normalizedReplies.map((reply) => commentIsValid(reply, { validateReplies: false, blockCommunity }, pkc)));
333
+ return !repliesValidity.includes(false);
338
334
  });
339
335
  const utils = {
340
336
  merge,
@@ -345,7 +341,9 @@ const utils = {
345
341
  retryInfinity: (f, o) => { },
346
342
  // export timeout values to mock them in tests
347
343
  retryInfinityMinTimeout: 1000,
348
- retryInfinityMaxTimeout: 1000 * 60 * 60 * 24,
344
+ // the page stores keep a fetch pending while it sleeps between retries, so a longer cap would
345
+ // keep that page from loading for about as long as an outage lasted
346
+ retryInfinityMaxTimeout: 1000 * 60,
349
347
  clientsOnStateChange,
350
348
  pageClientsOnStateChange,
351
349
  communityPostsCacheExpired,
@@ -353,8 +351,11 @@ const utils = {
353
351
  removeInvalidComments,
354
352
  repliesAreValid,
355
353
  };
354
+ // options.shouldRetry lets the caller stop retrying, e.g. once the client functionToRetry uses was
355
+ // replaced, it's checked after each failed attempt and after each sleep, and rejects with the last error
356
356
  const retryInfinity = (functionToRetry, options) => __awaiter(void 0, void 0, void 0, function* () {
357
357
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
358
+ const shouldRetry = () => !(options === null || options === void 0 ? void 0 : options.shouldRetry) || options.shouldRetry();
358
359
  let attempt = 0;
359
360
  while (true) {
360
361
  try {
@@ -362,11 +363,18 @@ const retryInfinity = (functionToRetry, options) => __awaiter(void 0, void 0, vo
362
363
  return res;
363
364
  }
364
365
  catch (e) {
365
- options === null || options === void 0 ? void 0 : options.onError(e || Error(`retryInfinity failed attempt ${attempt}`));
366
+ const error = e || Error(`retryInfinity failed attempt ${attempt}`);
367
+ options === null || options === void 0 ? void 0 : options.onError(error);
368
+ if (!shouldRetry()) {
369
+ throw error;
370
+ }
366
371
  const factor = 2;
367
372
  let timeout = Math.round(utils.retryInfinityMinTimeout * Math.pow(factor, attempt++));
368
373
  timeout = Math.min(timeout, utils.retryInfinityMaxTimeout);
369
374
  yield sleep(timeout);
375
+ if (!shouldRetry()) {
376
+ throw error;
377
+ }
370
378
  }
371
379
  }
372
380
  });
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAG7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAAmC,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAElD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;IAC7B,aAAa;IACb,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAClC,MAAM,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,yBAAyB,GAAG,iBAAiB,CAAC,CAAC;QACtF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,MAAM,SAAS,GAAQ,EAAE,CAAC;IAC1B,OAAO,UAAU,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;QACtC,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;YAC3B,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC1D,SAAS;YACX,CAAC;YACD,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,CAA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AqB;IACrB,eAAe;CAChB,CAAC;AAEF,MAAM,aAAa,GAAG,CAAO,eAAoB,EAAE,OAAa,EAAE,EAAE;IAClE,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACpE,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,eAAe,EAAE,CAAC;YACpC,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,gCAAgC,OAAO,EAAE,CAAC,CAAC,CAAC;YACxE,MAAM,MAAM,GAAG,CAAC,CAAC;YACjB,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YACtF,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3D,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC,CAAA,CAAC;AACF,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AAEpC,eAAe,KAAK,CAAC","sourcesContent":["import assert from \"../assert\";\nimport QuickLru from \"quick-lru\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport PkcJs from \"../pkc-js\";\nimport { Comment } from \"../../types\";\nimport { areEquivalentCommunityAddresses } from \"../community-address\";\nimport { getCommentCommunityAddress, normalizePublicationOptionsForStore } from \"../pkc-compat\";\nimport { getPageRpcClients } from \"../pkc-compat\";\nconst log = Logger(\"bitsocial-react-hooks:utils\");\n\nconst merge = (...args: any) => {\n // @ts-ignore\n const clonedArgs = args.map((arg) => {\n assert(arg && typeof arg === \"object\", `utils.merge argument '${arg}' not an object`);\n return clone(arg);\n });\n const mergedObj: any = {};\n while (clonedArgs.length) {\n const currentArg = clonedArgs.shift();\n for (const i in currentArg) {\n if (currentArg[i] === undefined || currentArg[i] === null) {\n continue;\n }\n mergedObj[i] = currentArg[i];\n }\n }\n return mergedObj;\n};\n\nconst clone = (obj: any) => {\n assert(obj && typeof obj === \"object\", `utils.clone argument '${obj}' not an object`);\n let clonedObj: any = {};\n\n // clean the object to be cloned\n for (const i in obj) {\n // remove functions\n if (typeof obj[i] === \"function\") {\n continue;\n }\n // remove internal props\n if (i.startsWith(\"_\")) {\n continue;\n }\n if (obj[i] === undefined || obj[i] === null) {\n continue;\n }\n // pkc-js has a bug where pkc instances have circular deps\n if (obj[i]?.constructor?.name === \"PKC\") {\n continue;\n }\n clonedObj[i] = obj[i];\n }\n\n // clone the object\n clonedObj = JSON.parse(JSON.stringify(clonedObj));\n return clonedObj;\n};\n\n// this function should not clone the comments to not waste memory\nexport const flattenCommentsPages = (pageInstanceOrPagesInstance: any) => {\n const flattenedComments = [];\n\n // if is a Page instance\n if (pageInstanceOrPagesInstance?.comments) {\n for (const comment of pageInstanceOrPagesInstance.comments) {\n flattenedComments.push(comment);\n if (comment.replies?.pages && Object.keys(comment.replies.pages).length) {\n flattenedComments.push(...flattenCommentsPages(comment.replies));\n }\n }\n }\n\n // if is a Pages instance\n else if (pageInstanceOrPagesInstance?.pages) {\n for (const sortType in pageInstanceOrPagesInstance.pages) {\n flattenedComments.push(...flattenCommentsPages(pageInstanceOrPagesInstance.pages[sortType]));\n }\n }\n\n // if is a Pages.pages instance\n else {\n for (const sortType in pageInstanceOrPagesInstance) {\n const page = pageInstanceOrPagesInstance[sortType];\n if (page?.comments?.length) {\n flattenedComments.push(...flattenCommentsPages(page));\n }\n }\n }\n\n // remove duplicate comments\n const flattenedCommentsObject = {};\n for (const comment of flattenedComments) {\n // @ts-ignore\n flattenedCommentsObject[comment.cid] = comment;\n }\n const uniqueFlattened = [];\n for (const cid in flattenedCommentsObject) {\n // @ts-ignore\n uniqueFlattened.push(flattenedCommentsObject[cid]);\n }\n\n return uniqueFlattened;\n};\n\nconst memo = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const pendingPromises: any = new Map();\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: async (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // don't request the same thing twice if fetching is pending\n let pendingPromise = pendingPromises.get(cacheKey);\n if (pendingPromise) {\n return pendingPromise;\n }\n\n // create the pending promise\n let resolve: any, reject: any;\n pendingPromise = new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n pendingPromises.set(cacheKey, pendingPromise);\n\n // execute the function\n try {\n const result = await functionToMemo(...args);\n cache.set(cacheKey, result);\n pendingPromises.delete(cacheKey);\n resolve?.(result);\n } catch (error) {\n pendingPromises.delete(cacheKey);\n reject?.(error);\n }\n\n return pendingPromise;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst memoSync = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // execute the function\n const result = functionToMemo(...args);\n if (typeof result?.then === \"function\") {\n throw Error(\n `memoed function '${memoedFunctionName}' is an async function, cannot be used with memoSync, use memo instead`,\n );\n }\n cache.set(cacheKey, result);\n return result;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst clientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const clientUrl in clients?.ipfsGateways) {\n clients?.ipfsGateways?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", clientUrl),\n );\n }\n for (const clientUrl in clients?.kuboRpcClients) {\n clients?.kuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.pubsubKuboRpcClients) {\n clients?.pubsubKuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pubsubKuboRpcClients\", clientUrl),\n );\n }\n const rpcClients = getPageRpcClients(clients);\n for (const clientUrl in rpcClients) {\n rpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.libp2pJsClients) {\n clients?.libp2pJsClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", clientUrl),\n );\n }\n for (const chainTicker in clients?.chainProviders) {\n for (const clientUrl in clients?.chainProviders?.[chainTicker]) {\n clients?.chainProviders?.[chainTicker]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"chainProviders\", clientUrl, chainTicker),\n );\n }\n }\n for (const resolverKey in clients?.nameResolvers) {\n clients?.nameResolvers?.[resolverKey].on(\"statechange\", (state: string) =>\n onStateChange(state, \"nameResolvers\", resolverKey),\n );\n }\n};\n\nconst pageClientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const sortType in clients?.ipfsGateways) {\n for (const clientUrl in clients?.ipfsGateways?.[sortType]) {\n clients?.ipfsGateways?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.kuboRpcClients) {\n for (const clientUrl in clients?.kuboRpcClients?.[sortType]) {\n clients?.kuboRpcClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", sortType, clientUrl),\n );\n }\n }\n const rpcPageClients = getPageRpcClients(clients);\n for (const sortType in rpcPageClients) {\n for (const clientUrl in rpcPageClients?.[sortType]) {\n rpcPageClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.libp2pJsClients) {\n for (const clientUrl in clients?.libp2pJsClients?.[sortType]) {\n clients?.libp2pJsClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", sortType, clientUrl),\n );\n }\n }\n};\n\nexport const communityPostsCacheExpired = (community: any) => {\n // NOTE: fetchedAt is undefined on owner communities\n if (!community || community.fetchedAt == null) {\n return false;\n }\n // if community cache is older than 1 hour, its community.posts are considered expired\n const oneHourAgo = Date.now() / 1000 - 60 * 60;\n return oneHourAgo > community.fetchedAt;\n};\n\nexport const removeInvalidComments = async (\n comments: Comment[],\n { validateReplies, blockCommunity }: any,\n pkc: any,\n) => {\n if (!comments.length) {\n return [];\n }\n const isValid = await Promise.all(\n comments.map((comment) => commentIsValid(comment, { validateReplies, blockCommunity }, pkc)),\n );\n const validComments = comments.filter((_, i) => isValid[i]);\n return validComments;\n};\n\nconst communitiesWithInvalidComments: { [communityAddress: string]: boolean } = {};\nexport const commentIsValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n if (communitiesWithInvalidComments[comment.communityAddress]) {\n console.log(\n `community '${comment.communityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n try {\n await pkc.validateComment(comment, { validateReplies });\n } catch (e) {\n if (blockCommunity) {\n communitiesWithInvalidComments[comment.communityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst repliesAreValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress && communitiesWithInvalidComments[commentCommunityAddress]) {\n console.log(\n `community '${commentCommunityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n const replyPageArray: any[] = Object.values(comment.replies?.pages || {});\n const replies = replyPageArray.flatMap((replyPage: any) => replyPage?.comments || []);\n const normalizedReplies = replies.map((reply) => {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) || commentCommunityAddress;\n return normalizedReply;\n });\n\n // manual validation\n for (const reply of normalizedReplies) {\n if (\n !areEquivalentCommunityAddresses(\n getCommentCommunityAddress(reply),\n commentCommunityAddress,\n ) ||\n reply.depth !== comment.depth + 1 ||\n reply.parentCid !== comment.cid\n ) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", {\n comment: reply,\n error:\n \"!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress) || reply.depth !== comment.depth + 1 || reply.parentCid !== comment.cid\",\n });\n return false;\n }\n }\n\n // signature verification\n try {\n const promises = normalizedReplies.map((reply) =>\n commentIsValid(reply, { validateReplies: false, blockCommunity: true }, pkc),\n );\n await Promise.all(promises);\n } catch (e: any) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst utils = {\n merge,\n clone,\n flattenCommentsPages,\n memo,\n memoSync,\n retryInfinity: (f: any, o?: any): any => {},\n // export timeout values to mock them in tests\n retryInfinityMinTimeout: 1000,\n retryInfinityMaxTimeout: 1000 * 60 * 60 * 24,\n clientsOnStateChange,\n pageClientsOnStateChange,\n communityPostsCacheExpired,\n commentIsValid,\n removeInvalidComments,\n repliesAreValid,\n};\n\nconst retryInfinity = async (functionToRetry: any, options?: any) => {\n const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n let attempt = 0;\n while (true) {\n try {\n const res = await functionToRetry();\n return res;\n } catch (e) {\n options?.onError(e || Error(`retryInfinity failed attempt ${attempt}`));\n const factor = 2;\n let timeout = Math.round(utils.retryInfinityMinTimeout * Math.pow(factor, attempt++));\n timeout = Math.min(timeout, utils.retryInfinityMaxTimeout);\n await sleep(timeout);\n }\n }\n};\nutils.retryInfinity = retryInfinity;\n\nexport default utils;\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,yBAAyB,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AE,CAAC;IACzE,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,eAAe,EAAE,CAAC;YACpC,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,gCAAgC,OAAO,EAAE,CAAC,CAAC;YACpE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBACnB,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,MAAM,GAAG,CAAC,CAAC;YACjB,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YACtF,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3D,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;YACrB,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBACnB,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA,CAAC;AACF,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AAEpC,eAAe,KAAK,CAAC","sourcesContent":["import assert from \"../assert\";\nimport QuickLru from \"quick-lru\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nimport PkcJs from \"../pkc-js\";\nimport { Comment } from \"../../types\";\nimport { areEquivalentCommunityAddresses } from \"../community-address\";\nimport { getCommentCommunityAddress, normalizePublicationOptionsForStore } from \"../pkc-compat\";\nimport { getPageRpcClients } from \"../pkc-compat\";\nconst log = Logger(\"bitsocial-react-hooks:utils\");\n\nconst merge = (...args: any) => {\n // @ts-ignore\n const clonedArgs = args.map((arg) => {\n assert(arg && typeof arg === \"object\", `utils.merge argument '${arg}' not an object`);\n return clone(arg);\n });\n const mergedObj: any = {};\n while (clonedArgs.length) {\n const currentArg = clonedArgs.shift();\n for (const i in currentArg) {\n if (currentArg[i] === undefined || currentArg[i] === null) {\n continue;\n }\n mergedObj[i] = currentArg[i];\n }\n }\n return mergedObj;\n};\n\nconst clone = (obj: any) => {\n assert(obj && typeof obj === \"object\", `utils.clone argument '${obj}' not an object`);\n let clonedObj: any = {};\n\n // clean the object to be cloned\n for (const i in obj) {\n // remove functions\n if (typeof obj[i] === \"function\") {\n continue;\n }\n // remove internal props\n if (i.startsWith(\"_\")) {\n continue;\n }\n if (obj[i] === undefined || obj[i] === null) {\n continue;\n }\n // pkc-js has a bug where pkc instances have circular deps\n if (obj[i]?.constructor?.name === \"PKC\") {\n continue;\n }\n clonedObj[i] = obj[i];\n }\n\n // clone the object\n clonedObj = JSON.parse(JSON.stringify(clonedObj));\n return clonedObj;\n};\n\n// this function should not clone the comments to not waste memory\nexport const flattenCommentsPages = (pageInstanceOrPagesInstance: any) => {\n const flattenedComments = [];\n\n // if is a Page instance\n if (pageInstanceOrPagesInstance?.comments) {\n for (const comment of pageInstanceOrPagesInstance.comments) {\n flattenedComments.push(comment);\n if (comment.replies?.pages && Object.keys(comment.replies.pages).length) {\n flattenedComments.push(...flattenCommentsPages(comment.replies));\n }\n }\n }\n\n // if is a Pages instance\n else if (pageInstanceOrPagesInstance?.pages) {\n for (const sortType in pageInstanceOrPagesInstance.pages) {\n flattenedComments.push(...flattenCommentsPages(pageInstanceOrPagesInstance.pages[sortType]));\n }\n }\n\n // if is a Pages.pages instance\n else {\n for (const sortType in pageInstanceOrPagesInstance) {\n const page = pageInstanceOrPagesInstance[sortType];\n if (page?.comments?.length) {\n flattenedComments.push(...flattenCommentsPages(page));\n }\n }\n }\n\n // remove duplicate comments\n const flattenedCommentsObject = {};\n for (const comment of flattenedComments) {\n // @ts-ignore\n flattenedCommentsObject[comment.cid] = comment;\n }\n const uniqueFlattened = [];\n for (const cid in flattenedCommentsObject) {\n // @ts-ignore\n uniqueFlattened.push(flattenedCommentsObject[cid]);\n }\n\n return uniqueFlattened;\n};\n\nconst memo = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const pendingPromises: any = new Map();\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: async (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // don't request the same thing twice if fetching is pending\n let pendingPromise = pendingPromises.get(cacheKey);\n if (pendingPromise) {\n return pendingPromise;\n }\n\n // create the pending promise\n let resolve: any, reject: any;\n pendingPromise = new Promise((_resolve, _reject) => {\n resolve = _resolve;\n reject = _reject;\n });\n pendingPromises.set(cacheKey, pendingPromise);\n\n // execute the function\n try {\n const result = await functionToMemo(...args);\n cache.set(cacheKey, result);\n pendingPromises.delete(cacheKey);\n resolve?.(result);\n } catch (error) {\n pendingPromises.delete(cacheKey);\n reject?.(error);\n }\n\n return pendingPromise;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst memoSync = (functionToMemo: Function, memoOptions: any) => {\n assert(typeof functionToMemo === \"function\", `memo first argument must be a function`);\n const cache = new QuickLru(memoOptions);\n\n // preserve function name\n const memoedFunctionName = functionToMemo.name || \"memoedFunction\";\n const obj = {\n [memoedFunctionName]: (...args: any) => {\n let cacheKey = args[0];\n if (args.length > 1) {\n cacheKey = \"\";\n for (const arg of args) {\n if (\n typeof arg !== \"string\" &&\n typeof arg !== \"number\" &&\n arg !== undefined &&\n arg !== null\n ) {\n const argumentIndex = args.indexOf(arg);\n throw Error(\n `memoed function '${memoedFunctionName}' invalid argument number '${argumentIndex}' '${arg}', memoed function can only use multiple arguments if they are all of type string, number, undefined or null`,\n );\n }\n cacheKey += arg;\n }\n }\n\n // has cached result\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n // execute the function\n const result = functionToMemo(...args);\n if (typeof result?.then === \"function\") {\n throw Error(\n `memoed function '${memoedFunctionName}' is an async function, cannot be used with memoSync, use memo instead`,\n );\n }\n cache.set(cacheKey, result);\n return result;\n },\n };\n return obj[memoedFunctionName];\n};\n\nconst clientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const clientUrl in clients?.ipfsGateways) {\n clients?.ipfsGateways?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", clientUrl),\n );\n }\n for (const clientUrl in clients?.kuboRpcClients) {\n clients?.kuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.pubsubKuboRpcClients) {\n clients?.pubsubKuboRpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pubsubKuboRpcClients\", clientUrl),\n );\n }\n const rpcClients = getPageRpcClients(clients);\n for (const clientUrl in rpcClients) {\n rpcClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", clientUrl),\n );\n }\n for (const clientUrl in clients?.libp2pJsClients) {\n clients?.libp2pJsClients?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", clientUrl),\n );\n }\n for (const chainTicker in clients?.chainProviders) {\n for (const clientUrl in clients?.chainProviders?.[chainTicker]) {\n clients?.chainProviders?.[chainTicker]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"chainProviders\", clientUrl, chainTicker),\n );\n }\n }\n for (const resolverKey in clients?.nameResolvers) {\n clients?.nameResolvers?.[resolverKey].on(\"statechange\", (state: string) =>\n onStateChange(state, \"nameResolvers\", resolverKey),\n );\n }\n};\n\nconst pageClientsOnStateChange = (clients: any, onStateChange: Function) => {\n for (const sortType in clients?.ipfsGateways) {\n for (const clientUrl in clients?.ipfsGateways?.[sortType]) {\n clients?.ipfsGateways?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"ipfsGateways\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.kuboRpcClients) {\n for (const clientUrl in clients?.kuboRpcClients?.[sortType]) {\n clients?.kuboRpcClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"kuboRpcClients\", sortType, clientUrl),\n );\n }\n }\n const rpcPageClients = getPageRpcClients(clients);\n for (const sortType in rpcPageClients) {\n for (const clientUrl in rpcPageClients?.[sortType]) {\n rpcPageClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"pkcRpcClients\", sortType, clientUrl),\n );\n }\n }\n for (const sortType in clients?.libp2pJsClients) {\n for (const clientUrl in clients?.libp2pJsClients?.[sortType]) {\n clients?.libp2pJsClients?.[sortType]?.[clientUrl].on(\"statechange\", (state: string) =>\n onStateChange(state, \"libp2pJsClients\", sortType, clientUrl),\n );\n }\n }\n};\n\nexport const communityPostsCacheExpired = (community: any) => {\n // NOTE: fetchedAt is undefined on owner communities\n if (!community || community.fetchedAt == null) {\n return false;\n }\n // if community cache is older than 1 hour, its community.posts are considered expired\n const oneHourAgo = Date.now() / 1000 - 60 * 60;\n return oneHourAgo > community.fetchedAt;\n};\n\nexport const removeInvalidComments = async (\n comments: Comment[],\n { validateReplies, blockCommunity }: any,\n pkc: any,\n) => {\n if (!comments.length) {\n return [];\n }\n const isValid = await Promise.all(\n comments.map((comment) => commentIsValid(comment, { validateReplies, blockCommunity }, pkc)),\n );\n const validComments = comments.filter((_, i) => isValid[i]);\n return validComments;\n};\n\nconst communitiesWithInvalidComments: { [communityAddress: string]: boolean } = {};\nexport const commentIsValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n if (communitiesWithInvalidComments[comment.communityAddress]) {\n console.log(\n `community '${comment.communityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n // without a pkc client, e.g. for a feed whose account was deleted, the comment can't be validated,\n // which says nothing about its community, so don't block it\n if (typeof pkc?.validateComment !== \"function\") {\n return false;\n }\n try {\n await pkc.validateComment(comment, { validateReplies });\n } catch (e) {\n if (blockCommunity && comment.communityAddress) {\n communitiesWithInvalidComments[comment.communityAddress] = true;\n }\n console.log(\"invalid comment\", { comment, error: e });\n return false;\n }\n return true;\n};\n\nconst repliesAreValid = async (\n comment: Comment,\n { validateReplies, blockCommunity }: any = {},\n pkc: any,\n) => {\n validateReplies = Boolean(validateReplies);\n if (blockCommunity === undefined || blockCommunity === null) {\n blockCommunity = true;\n }\n if (!comment) {\n return false;\n }\n const commentCommunityAddress = getCommentCommunityAddress(comment);\n if (commentCommunityAddress && communitiesWithInvalidComments[commentCommunityAddress]) {\n console.log(\n `community '${commentCommunityAddress}' had an invalid comment, invalidate all its future comments to avoid wasting resources`,\n );\n return false;\n }\n const replyPageArray: any[] = Object.values(comment.replies?.pages || {});\n const replies = replyPageArray.flatMap((replyPage: any) => replyPage?.comments || []);\n const normalizedReplies = replies.map((reply) => {\n const normalizedReply = normalizePublicationOptionsForStore(reply) as Comment;\n normalizedReply.communityAddress =\n getCommentCommunityAddress(normalizedReply) || commentCommunityAddress;\n return normalizedReply;\n });\n\n // manual validation\n for (const reply of normalizedReplies) {\n if (\n !areEquivalentCommunityAddresses(\n getCommentCommunityAddress(reply),\n commentCommunityAddress,\n ) ||\n reply.depth !== comment.depth + 1 ||\n reply.parentCid !== comment.cid\n ) {\n if (blockCommunity && commentCommunityAddress) {\n communitiesWithInvalidComments[commentCommunityAddress] = true;\n }\n console.log(\"invalid comment\", {\n comment: reply,\n error:\n \"!areEquivalentCommunityAddresses(reply.communityAddress, comment.communityAddress) || reply.depth !== comment.depth + 1 || reply.parentCid !== comment.cid\",\n });\n return false;\n }\n }\n\n // signature verification, commentIsValid returns false instead of throwing, and blocks the\n // community of an invalid reply itself\n const repliesValidity = await Promise.all(\n normalizedReplies.map((reply) =>\n commentIsValid(reply, { validateReplies: false, blockCommunity }, pkc),\n ),\n );\n return !repliesValidity.includes(false);\n};\n\nconst utils = {\n merge,\n clone,\n flattenCommentsPages,\n memo,\n memoSync,\n retryInfinity: (f: any, o?: any): any => {},\n // export timeout values to mock them in tests\n retryInfinityMinTimeout: 1000,\n // the page stores keep a fetch pending while it sleeps between retries, so a longer cap would\n // keep that page from loading for about as long as an outage lasted\n retryInfinityMaxTimeout: 1000 * 60,\n clientsOnStateChange,\n pageClientsOnStateChange,\n communityPostsCacheExpired,\n commentIsValid,\n removeInvalidComments,\n repliesAreValid,\n};\n\n// options.shouldRetry lets the caller stop retrying, e.g. once the client functionToRetry uses was\n// replaced, it's checked after each failed attempt and after each sleep, and rejects with the last error\nconst retryInfinity = async (functionToRetry: any, options?: any) => {\n const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));\n const shouldRetry = () => !options?.shouldRetry || options.shouldRetry();\n let attempt = 0;\n while (true) {\n try {\n const res = await functionToRetry();\n return res;\n } catch (e) {\n const error = e || Error(`retryInfinity failed attempt ${attempt}`);\n options?.onError(error);\n if (!shouldRetry()) {\n throw error;\n }\n const factor = 2;\n let timeout = Math.round(utils.retryInfinityMinTimeout * Math.pow(factor, attempt++));\n timeout = Math.min(timeout, utils.retryInfinityMaxTimeout);\n await sleep(timeout);\n if (!shouldRetry()) {\n throw error;\n }\n }\n }\n};\nutils.retryInfinity = retryInfinity;\n\nexport default utils;\n"]}
@@ -20,7 +20,7 @@ declare const validator: {
20
20
  validateUseCommunitiesArguments: ({ communities, communityRefs, communityAddresses, account, }: any) => void;
21
21
  validateUseCommunitiesStatesArguments: ({ communities, communityRefs, communityAddresses, }: any) => void;
22
22
  validateFeedSortType: (sortType: any) => void;
23
- validateUseFeedArguments: ({ communities, communityRefs, communityAddresses, sortType, accountName, postsPerPage, filter, newerThan, accountComments, }: any) => void;
23
+ validateUseFeedArguments: ({ communities, communityRefs, communityAddresses, sortType, accountName, postsPerPage, filter, newerThan, accountComments, includeBlockedCids, }: any) => void;
24
24
  validateUseBufferedFeedsArguments: ({ feedsOptions, accountName, }: {
25
25
  feedsOptions?: any;
26
26
  accountName?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AA6sBA,QAAA,MAAM,SAAS;uGAvrBZ,GAAG;+GAkIH,GAAG;2HA4CH,GAAG;qIA6FH,GAAG;8EAZ2E,GAAG;iGA/KjF,GAAG;iEAsO8D,GAAG;+EAS7C,GAAG,gBACb,GAAG;0DAQ0C,GAAG;0DArFH,GAAG,kBAAkB,GAAG;oEAgGd,GAAG;2DAuCZ,GAAG;+DA/BC,GAAG;yDAkBT,GAAG;8CA8Bd,GAAG,WAAW,GAAG;gDAQf,GAAG,WAAW,GAAG;8EAgCa,GAAG;0EAUP,GAAG;oGAqC7E,GAAG;iGAqIH,GAAG;qCA3HkC,GAAG;6JAgBxC,GAAG;wEA6CH;QACD,YAAY,CAAC,EAAE,GAAG,CAAC;QACnB,WAAW,CAAC,EAAE,GAAG,CAAC;KACnB;wCAoE0C,GAAG;4CAOlC,GAAG,aACF,GAAG,gBACA,GAAG,iBACF,GAAG,SACX,GAAG,oBACQ,GAAG,iBACN,GAAG,WACT,GAAG;CAmFb,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AA8tBA,QAAA,MAAM,SAAS;uGAxsBZ,GAAG;+GAkIH,GAAG;2HA4CH,GAAG;qIA6FH,GAAG;8EAZ2E,GAAG;iGA/KjF,GAAG;iEAsO8D,GAAG;+EAS7C,GAAG,gBACb,GAAG;0DAQ0C,GAAG;0DArFH,GAAG,kBAAkB,GAAG;oEAgGd,GAAG;2DAuCZ,GAAG;+DA/BC,GAAG;yDAkBT,GAAG;8CA8Bd,GAAG,WAAW,GAAG;gDAQf,GAAG,WAAW,GAAG;8EAgCa,GAAG;0EAUP,GAAG;oGAqC7E,GAAG;iGAkJH,GAAG;qCAxIkC,GAAG;iLAmBxC,GAAG;wEAuDH;QACD,YAAY,CAAC,EAAE,GAAG,CAAC;QACnB,WAAW,CAAC,EAAE,GAAG,CAAC;KACnB;wCAoE0C,GAAG;4CAOlC,GAAG,aACF,GAAG,gBACA,GAAG,iBACF,GAAG,SACX,GAAG,oBACQ,GAAG,iBACN,GAAG,WACT,GAAG;CAuFb,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -205,7 +205,8 @@ const validateUseCommunitiesArguments = ({ communities, communityRefs, community
205
205
  const validateFeedSortType = (sortType) => {
206
206
  assert(sortType === undefined || (typeof sortType === "string" && sortType.length > 0), `invalid feed sort type '${sortType}'`);
207
207
  };
208
- const validateUseFeedArguments = ({ communities, communityRefs, communityAddresses, sortType, accountName, postsPerPage, filter, newerThan, accountComments, }) => {
208
+ const isValidAccountCommentsLimit = (limit) => limit === undefined || limit === null || (Number.isInteger(limit) && limit >= 0);
209
+ const validateUseFeedArguments = ({ communities, communityRefs, communityAddresses, sortType, accountName, postsPerPage, filter, newerThan, accountComments, includeBlockedCids, }) => {
209
210
  validateCommunitiesArguments(communities, communityRefs, communityAddresses, "useFeed");
210
211
  assert(sortType === undefined || (typeof sortType === "string" && sortType.length > 0), `useFeed sortType argument '${sortType}' invalid`);
211
212
  if (accountName) {
@@ -224,6 +225,10 @@ const validateUseFeedArguments = ({ communities, communityRefs, communityAddress
224
225
  if (accountComments) {
225
226
  assert(typeof accountComments === "object", `useFeed accountComments argument '${accountComments}' not an object`);
226
227
  assert(typeof accountComments.newerThan === "number", `useFeed accountComments.newerThan argument '${accountComments}' not a number`);
228
+ assert(isValidAccountCommentsLimit(accountComments.limit), `useFeed accountComments.limit argument '${accountComments.limit}' not a non-negative integer`);
229
+ }
230
+ if (includeBlockedCids !== undefined && includeBlockedCids !== null) {
231
+ assert(typeof includeBlockedCids === "boolean", `useFeed includeBlockedCids argument '${includeBlockedCids}' not a boolean`);
227
232
  }
228
233
  };
229
234
  const validateUseBufferedFeedsArguments = ({ feedsOptions, accountName, }) => {
@@ -271,6 +276,7 @@ const validateUseRepliesArguments = (comment, sortType, accountName, onlyIfCache
271
276
  if (accountComments !== undefined && accountComments !== null) {
272
277
  assert(typeof accountComments.newerThan === "number", `useReplies accountComments.newerThan argument '${accountComments.newerThan}' not a number`);
273
278
  assert(!accountComments.append || typeof accountComments.append === "boolean", `useReplies accountComments.append argument '${accountComments.append}' not a boolean`);
279
+ assert(isValidAccountCommentsLimit(accountComments.limit), `useReplies accountComments.limit argument '${accountComments.limit}' not a non-negative integer`);
274
280
  }
275
281
  if (filter) {
276
282
  assert(typeof filter.filter === "function", `useReplies filter.filter argument '${filter.filter}' not a function, useRepliesOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`);
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;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AAU,EACnC,sCAAsC,MAAM,CAAC,MAAM,yHAAyH,CAC7K,CAAC;QACF,MAAM,CACJ,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,EAC9B,mCAAmC,MAAM,CAAC,GAAG,yEAAyE,CACvH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG;IAChB,8CAA8C;IAC9C,kDAAkD;IAClD,wDAAwD;IACxD,oDAAoD;IACpD,+CAA+C;IAC/C,2CAA2C;IAC3C,6CAA6C;IAC7C,gDAAgD;IAChD,0CAA0C;IAC1C,2CAA2C;IAC3C,gDAAgD;IAChD,2CAA2C;IAC3C,4CAA4C;IAC5C,oCAAoC;IACpC,2BAA2B;IAC3B,4BAA4B;IAC5B,6BAA6B;IAC7B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;IACrC,oBAAoB;IACpB,wBAAwB;IACxB,iCAAiC;IACjC,uBAAuB;IACvB,2BAA2B;CAC5B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import assert from \"./assert\";\nimport { assertCommunityRef } from \"./community-ref\";\n\nconst toString = (value: any) => {\n if (typeof value === \"string\") {\n return value;\n }\n try {\n const string = JSON.stringify(value);\n return string;\n } catch {}\n return value;\n};\n\nconst getPublicationCommunityAddress = (options: any) =>\n options?.communityAddress || options?.communityAddress;\nconst getAccountProtocolClient = (account: any) => account?.pkc || account?.pkc;\n\nconst validateAccountsActionsPublishCommentArguments = ({\n publishCommentOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishComment accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishComment accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishComment no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentOptions && typeof publishCommentOptions === \"object\",\n \"publishComment publishCommentOptions not an object\",\n );\n assert(\n typeof publishCommentOptions.onChallenge === \"function\",\n \"publishComment publishCommentOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentOptions.onChallengeVerification === \"function\",\n \"publishComment publishCommentOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentOptions.onError || typeof publishCommentOptions.onError === \"function\",\n \"publishComment publishCommentOptions.onError not a function\",\n );\n assert(\n publishCommentOptions.onPendingComment == null ||\n typeof publishCommentOptions.onPendingComment === \"function\",\n \"publishComment publishCommentOptions.onPendingComment not a function\",\n );\n assert(\n publishCommentOptions.onBeforeRepublish == null ||\n typeof publishCommentOptions.onBeforeRepublish === \"function\",\n \"publishComment publishCommentOptions.onBeforeRepublish not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentOptions) === \"string\",\n \"publishComment publishCommentOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n !publishCommentOptions.parentCid || typeof publishCommentOptions.parentCid === \"string\",\n \"publishComment publishCommentOptions.parentCid not a string\",\n );\n assert(\n !publishCommentOptions.timestamp || typeof publishCommentOptions.timestamp === \"number\",\n \"publishComment publishCommentOptions.timestamp is not a number\",\n );\n\n // validate content\n assert(\n !publishCommentOptions.content || typeof publishCommentOptions.content === \"string\",\n \"publishComment publishCommentOptions.content not a string\",\n );\n assert(\n publishCommentOptions.content !== \"\",\n \"publishComment publishCommentOptions.content is an empty string\",\n );\n assert(\n !publishCommentOptions.link || typeof publishCommentOptions.link === \"string\",\n \"publishComment publishCommentOptions.link not a string\",\n );\n assert(\n publishCommentOptions.link !== \"\",\n \"publishComment publishCommentOptions.link is an empty string\",\n );\n assert(\n !publishCommentOptions.title || typeof publishCommentOptions.title === \"string\",\n \"publishComment publishCommentOptions.title not a string\",\n );\n assert(\n publishCommentOptions.title !== \"\",\n \"publishComment publishCommentOptions.title is an empty string\",\n );\n};\n\nconst validateAccountsActionsPublishVoteArguments = ({\n publishVoteOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishVote accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishVote accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishVote no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishVoteOptions && typeof publishVoteOptions === \"object\",\n \"publishVote publishVoteOptions not an object\",\n );\n assert(\n typeof publishVoteOptions.onChallenge === \"function\",\n \"publishVote publishVoteOptions.onChallenge not a function\",\n );\n assert(\n typeof publishVoteOptions.onChallengeVerification === \"function\",\n \"publishVote publishVoteOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishVoteOptions.onError || typeof publishVoteOptions.onError === \"function\",\n \"publishVote publishVoteOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishVoteOptions) === \"string\",\n \"publishVote publishVoteOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishVoteOptions.commentCid === \"string\",\n \"publishVote publishVoteOptions.commentCid not a string\",\n );\n assert(\n publishVoteOptions.vote === 1 ||\n publishVoteOptions.vote === 0 ||\n publishVoteOptions.vote === -1,\n \"publishVote publishVoteOptions.vote not 1, 0 or -1\",\n );\n assert(\n !publishVoteOptions.timestamp || typeof publishVoteOptions.timestamp === \"number\",\n \"publishVote publishVoteOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentEditArguments = ({\n publishCommentEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentEditOptions && typeof publishCommentEditOptions === \"object\",\n \"publishCommentEdit publishCommentEditOptions not an object\",\n );\n assert(\n typeof publishCommentEditOptions.onChallenge === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentEditOptions.onChallengeVerification === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentEditOptions.onError || typeof publishCommentEditOptions.onError === \"function\",\n \"publishCommentEditOptions publishCommentEditOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentEditOptions) === \"string\",\n \"publishCommentEdit publishCommentEditOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentEditOptions.commentCid === \"string\",\n \"publishCommentEdit publishCommentEditOptions.commentCid not a string\",\n );\n assert(\n !publishCommentEditOptions.timestamp || typeof publishCommentEditOptions.timestamp === \"number\",\n \"publishCommentEdit publishCommentEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentModerationArguments = ({\n publishCommentModerationOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentModeration accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentModeration accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentModeration no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentModerationOptions && typeof publishCommentModerationOptions === \"object\",\n \"publishCommentModeration publishCommentModerationOptions not an object\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallenge === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallengeVerification === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentModerationOptions.onError ||\n typeof publishCommentModerationOptions.onError === \"function\",\n \"publishCommentModerationOptions publishCommentModerationOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentModerationOptions) === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentModerationOptions.commentCid === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.commentCid not a string\",\n );\n assert(\n !publishCommentModerationOptions.timestamp ||\n typeof publishCommentModerationOptions.timestamp === \"number\",\n \"publishCommentModeration publishCommentModerationOptions.timestamp is not a number\",\n );\n assert(\n publishCommentModerationOptions.commentModeration &&\n typeof publishCommentModerationOptions.commentModeration === \"object\",\n \"publishCommentModeration publishCommentModerationOptions.commentModeration is not an object\",\n );\n};\n\n// communities reject a domain name with an uppercase letter, the same check as pkc-js\n// doesDomainAddressHaveCapitalLetter. public keys have no \".\" and are case-sensitive, so they are not checked\nconst assertDomainNameIsLowercase = (name: unknown, code: string, message: string) => {\n if (typeof name === \"string\" && name.includes(\".\") && /[A-Z]/.test(name)) {\n const error: Error & { code?: string } = new Error(message);\n error.code = code;\n throw error;\n }\n};\n\nconst validateCommunityNameIsLowercase = (options: any, optionsName: string) => {\n for (const field of [\"name\", \"address\"]) {\n assertDomainNameIsLowercase(\n options?.[field],\n \"ERR_COMMUNITY_NAME_HAS_CAPITAL_LETTER\",\n `${optionsName}.${field} '${options?.[field]}' has an uppercase letter, community names must be lowercase`,\n );\n }\n};\n\n// pkc-js publishes author.name, or author.address when the account stores its domain name there. only a\n// changed name is checked, so a name saved before this check does not block unrelated account edits\nconst validateAccountsActionsSetAccountAuthorName = (author: any, previousAuthor: any) => {\n for (const field of [\"name\", \"address\"]) {\n if (author?.[field] !== previousAuthor?.[field]) {\n assertDomainNameIsLowercase(\n author?.[field],\n \"ERR_AUTHOR_NAME_HAS_CAPITAL_LETTER\",\n `setAccount account.author.${field} '${author?.[field]}' has an uppercase letter, author names must be lowercase`,\n );\n }\n }\n};\n\nconst validateAccountsActionsCreateCommunityArguments = (createCommunityOptions: any) => {\n validateCommunityNameIsLowercase(\n createCommunityOptions,\n \"createCommunity createCommunityOptions\",\n );\n};\n\nconst validateAccountsActionsPublishCommunityEditArguments = ({\n communityAddress,\n publishCommunityEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommunityEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommunityEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommunityEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommunityEditOptions && typeof publishCommunityEditOptions === \"object\",\n \"publishCommunityEdit publishCommunityEditOptions not an object\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallenge === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallengeVerification === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommunityEditOptions.onError ||\n typeof publishCommunityEditOptions.onError === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onError not a function\",\n );\n assert(communityAddress !== \"\", `publishCommunityEdit communityAddress argument is empty string`);\n assert(\n typeof communityAddress === \"string\",\n \"publishCommunityEdit communityAddress not a string\",\n );\n assert(\n !publishCommunityEditOptions.timestamp ||\n typeof publishCommunityEditOptions.timestamp === \"number\",\n \"publishCommunityEdit publishCommunityEditOptions.timestamp is not a number\",\n );\n validateCommunityNameIsLowercase(\n publishCommunityEditOptions,\n \"publishCommunityEdit publishCommunityEditOptions\",\n );\n};\n\nconst validateAccountsActionsExportAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `exportAccount accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `exportAccount accountName argument is empty string`);\n};\n\nconst validateAccountsActionsSetAccountsOrderArguments = (\n newOrderedAccountNames: any,\n accountNames: any,\n) => {\n assert(\n JSON.stringify([...accountNames].sort()) === JSON.stringify([...newOrderedAccountNames].sort()),\n `previous account names '${accountNames} contain different account names than argument newOrderedAccountNames '${newOrderedAccountNames}'`,\n );\n};\n\nconst validateAccountsActionsSetAccountArguments = (account: any) => {\n assert(account && typeof account === \"object\", `setAccount account '${account}' not an object`);\n assert(\n typeof account.name === \"string\",\n `setAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `setAccount account.name is empty string`);\n assert(typeof account.id === \"string\", `setAccount account.id '${account.id}' not a string`);\n assert(account.id !== \"\", `setAccount account.id is empty string`);\n};\n\nconst validateAccountsActionsSetActiveAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `setActiveAccountName accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `setActiveAccountName accountName argument is empty string`);\n};\n\nconst validateAccountsDatabaseGetAccountsArguments = (accountIds: any) => {\n assert(\n Array.isArray(accountIds),\n `accountsDatabase.getAccounts accountIds '${accountIds}' not an array`,\n );\n assert(accountIds.length > 0, `accountsDatabase.getAccounts accountIds array is empty`);\n for (const accountId of accountIds) {\n assert(\n typeof accountId === \"string\",\n `accountsDatabase.getAccountsaccountIds '${accountIds}' accountId '${accountId}' not a string`,\n );\n assert(\n accountId !== \"\",\n `accountsDatabase.getAccounts accountIds '${accountIds}' an accountId argument is empty string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAccountNames = (accountNames: any) => {\n assert(\n Array.isArray(accountNames),\n `accountsDatabase accountNames '${accountNames}' not an array`,\n );\n for (const accountName of accountNames) {\n assert(\n typeof accountName === \"string\",\n `accountsDatabase accountNames '${accountNames}' accountName '${accountName}' not a string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAddAccountArguments = (account: any) => {\n assert(\n account && typeof account === \"object\",\n `accountsDatabase.addAccount '${account}' not an object`,\n );\n assert(\n typeof account.name === \"string\",\n `accountsDatabase.addAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `accountsDatabase.addAccount account.name is empty string`);\n assert(\n typeof account.id === \"string\",\n `accountsDatabase.addAccount account.id '${account.id}' not a string`,\n );\n assert(account.id !== \"\", `accountsDatabase.addAccount account.id is empty string`);\n};\n\nconst validateUseCommentArguments = (commentCid: any, account: any) => {\n assert(typeof commentCid === \"string\", `useComment commentCid '${commentCid}' not a string`);\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComment account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateUseCommentsArguments = (commentCids: any, account: any) => {\n assert(\n Array.isArray(commentCids),\n `useComment commentCids '${toString(commentCids)}' not an array`,\n );\n for (const commentCid of commentCids) {\n assert(\n typeof commentCid === \"string\",\n `useComments commentCids '${toString(commentCids)}' commentCid '${toString(commentCid)}' not a string`,\n );\n }\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComments account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateCommunityIdentifierArguments = (\n community: any,\n legacyCommunityAddress: any,\n scope: string,\n) => {\n assert(\n legacyCommunityAddress === undefined,\n `${scope} communityAddress has been removed, pass { community: { name, publicKey } }`,\n );\n if (community === undefined) {\n return;\n }\n assertCommunityRef(community, `${scope} community`);\n};\n\nconst validateUseCommunityArguments = ({ community, communityAddress, account }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunity\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateUseCommunityStatsArguments = ({ community, communityAddress }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunityStats\");\n};\n\nconst validateCommunitiesArguments = (\n communities: any,\n communityRefs: any,\n communityAddresses: any,\n scope: string,\n) => {\n assert(\n communityRefs === undefined,\n `${scope} communityRefs has been removed, pass communities instead`,\n );\n assert(\n communityAddresses === undefined,\n `${scope} communityAddresses has been removed, pass communities instead`,\n );\n if (communities !== undefined) {\n assert(\n Array.isArray(communities),\n `${scope} communities '${toString(communities)}' not an array`,\n );\n for (const community of communities) {\n assertCommunityRef(\n community,\n `${scope} communities '${toString(communities)}' community '${toString(community)}'`,\n );\n }\n }\n};\n\nconst validateUseCommunitiesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n account,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useCommunities\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateFeedSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid feed sort type '${sortType}'`,\n );\n};\nconst validateUseFeedArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useFeed\");\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useFeed sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useFeed accountName argument '${accountName}' not a string`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useFeed postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useFeed filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useFeed filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(typeof newerThan === \"number\", `useFeed newerThan argument '${newerThan}' not a number`);\n }\n if (accountComments) {\n assert(\n typeof accountComments === \"object\",\n `useFeed accountComments argument '${accountComments}' not an object`,\n );\n assert(\n typeof accountComments.newerThan === \"number\",\n `useFeed accountComments.newerThan argument '${accountComments}' not a number`,\n );\n }\n};\nconst validateUseBufferedFeedsArguments = ({\n feedsOptions,\n accountName,\n}: {\n feedsOptions?: any;\n accountName?: any;\n}) => {\n assert(\n Array.isArray(feedsOptions),\n `useBufferedFeeds feedsOptions argument '${toString(feedsOptions)}' not an array`,\n );\n for (const {\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n postsPerPage,\n filter,\n newerThan,\n } of feedsOptions) {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useBufferedFeeds feedOptions\",\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useBufferedFeeds feedOptions.sortType argument '${sortType}' invalid`,\n );\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useBufferedFeeds feedOptions.postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useBufferedFeeds feedOptions.filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useBufferedFeeds feedOptions.filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(\n typeof newerThan === \"number\",\n `useBufferedFeeds feedOptions.newerThan argument '${newerThan}' not a number`,\n );\n }\n }\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useBufferedFeeds accountName argument '${accountName}' not a string`,\n );\n }\n};\n\nconst validateUseCommunitiesStatesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n}: any) => {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useCommunitiesStates\",\n );\n};\n\nconst validateRepliesSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid replies sort type '${sortType}'`,\n );\n};\nconst validateUseRepliesArguments = (\n comment?: any,\n sortType?: any,\n accountName?: any,\n onlyIfCached?: any,\n flat?: any,\n accountComments?: any,\n postsPerPage?: any,\n filter?: any,\n) => {\n assert(\n !comment || typeof comment === \"object\",\n `useReplies comment argument '${comment}' not an object`,\n );\n assert(\n !comment?.cid || typeof comment.cid === \"string\",\n `useReplies comment.cid argument '${comment?.cid}' not a string`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useReplies sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useReplies accountName argument '${accountName}' not a string`,\n );\n }\n if (onlyIfCached !== undefined && onlyIfCached !== null) {\n assert(\n typeof onlyIfCached === \"boolean\",\n `useReplies onlyIfCached argument '${onlyIfCached}' not a boolean`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useReplies postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (flat !== undefined && flat !== null) {\n assert(typeof flat === \"boolean\", `useReplies flat argument '${flat}' not a boolean`);\n }\n if (accountComments !== undefined && accountComments !== null) {\n assert(\n typeof accountComments.newerThan === \"number\",\n `useReplies accountComments.newerThan argument '${accountComments.newerThan}' not a number`,\n );\n assert(\n !accountComments.append || typeof accountComments.append === \"boolean\",\n `useReplies accountComments.append argument '${accountComments.append}' not a boolean`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useReplies filter.filter argument '${filter.filter}' not a function, useRepliesOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useReplies filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n};\n\nconst validator = {\n validateAccountsActionsPublishCommentArguments,\n validateAccountsActionsPublishCommentEditArguments,\n validateAccountsActionsPublishCommentModerationArguments,\n validateAccountsActionsPublishCommunityEditArguments,\n validateAccountsActionsCreateCommunityArguments,\n validateAccountsActionsPublishVoteArguments,\n validateAccountsActionsExportAccountArguments,\n validateAccountsActionsSetAccountsOrderArguments,\n validateAccountsActionsSetAccountArguments,\n validateAccountsActionsSetAccountAuthorName,\n validateAccountsActionsSetActiveAccountArguments,\n validateAccountsDatabaseAddAccountArguments,\n validateAccountsDatabaseGetAccountsArguments,\n validateAccountsDatabaseAccountNames,\n validateUseCommentArguments,\n validateUseCommentsArguments,\n validateUseCommunityArguments,\n validateUseCommunityStatsArguments,\n validateUseCommunitiesArguments,\n validateUseCommunitiesStatesArguments,\n validateFeedSortType,\n validateUseFeedArguments,\n validateUseBufferedFeedsArguments,\n validateRepliesSortType,\n validateUseRepliesArguments,\n};\n\nexport default validator;\n"]}
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAE,EAAE;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;IACV,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,8BAA8B,GAAG,CAAC,OAAY,EAAE,EAAE,CACtD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAA,CAAC;AACzD,MAAM,wBAAwB,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAA,CAAC;AAEhF,MAAM,8CAA8C,GAAG,CAAC,EACtD,qBAAqB,EACrB,WAAW,EACX,OAAO,GACH,EAAE,EAAE;IACR,MAAM,CACJ,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAC/C,+BAA+B,WAAW,gBAAgB,CAC3D,CAAC;IACF,MAAM,CAAC,WAAW,KAAK,EAAE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AyE,CACvH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG;IAChB,8CAA8C;IAC9C,kDAAkD;IAClD,wDAAwD;IACxD,oDAAoD;IACpD,+CAA+C;IAC/C,2CAA2C;IAC3C,6CAA6C;IAC7C,gDAAgD;IAChD,0CAA0C;IAC1C,2CAA2C;IAC3C,gDAAgD;IAChD,2CAA2C;IAC3C,4CAA4C;IAC5C,oCAAoC;IACpC,2BAA2B;IAC3B,4BAA4B;IAC5B,6BAA6B;IAC7B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;IACrC,oBAAoB;IACpB,wBAAwB;IACxB,iCAAiC;IACjC,uBAAuB;IACvB,2BAA2B;CAC5B,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["import assert from \"./assert\";\nimport { assertCommunityRef } from \"./community-ref\";\n\nconst toString = (value: any) => {\n if (typeof value === \"string\") {\n return value;\n }\n try {\n const string = JSON.stringify(value);\n return string;\n } catch {}\n return value;\n};\n\nconst getPublicationCommunityAddress = (options: any) =>\n options?.communityAddress || options?.communityAddress;\nconst getAccountProtocolClient = (account: any) => account?.pkc || account?.pkc;\n\nconst validateAccountsActionsPublishCommentArguments = ({\n publishCommentOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishComment accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishComment accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishComment no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentOptions && typeof publishCommentOptions === \"object\",\n \"publishComment publishCommentOptions not an object\",\n );\n assert(\n typeof publishCommentOptions.onChallenge === \"function\",\n \"publishComment publishCommentOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentOptions.onChallengeVerification === \"function\",\n \"publishComment publishCommentOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentOptions.onError || typeof publishCommentOptions.onError === \"function\",\n \"publishComment publishCommentOptions.onError not a function\",\n );\n assert(\n publishCommentOptions.onPendingComment == null ||\n typeof publishCommentOptions.onPendingComment === \"function\",\n \"publishComment publishCommentOptions.onPendingComment not a function\",\n );\n assert(\n publishCommentOptions.onBeforeRepublish == null ||\n typeof publishCommentOptions.onBeforeRepublish === \"function\",\n \"publishComment publishCommentOptions.onBeforeRepublish not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentOptions) === \"string\",\n \"publishComment publishCommentOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n !publishCommentOptions.parentCid || typeof publishCommentOptions.parentCid === \"string\",\n \"publishComment publishCommentOptions.parentCid not a string\",\n );\n assert(\n !publishCommentOptions.timestamp || typeof publishCommentOptions.timestamp === \"number\",\n \"publishComment publishCommentOptions.timestamp is not a number\",\n );\n\n // validate content\n assert(\n !publishCommentOptions.content || typeof publishCommentOptions.content === \"string\",\n \"publishComment publishCommentOptions.content not a string\",\n );\n assert(\n publishCommentOptions.content !== \"\",\n \"publishComment publishCommentOptions.content is an empty string\",\n );\n assert(\n !publishCommentOptions.link || typeof publishCommentOptions.link === \"string\",\n \"publishComment publishCommentOptions.link not a string\",\n );\n assert(\n publishCommentOptions.link !== \"\",\n \"publishComment publishCommentOptions.link is an empty string\",\n );\n assert(\n !publishCommentOptions.title || typeof publishCommentOptions.title === \"string\",\n \"publishComment publishCommentOptions.title not a string\",\n );\n assert(\n publishCommentOptions.title !== \"\",\n \"publishComment publishCommentOptions.title is an empty string\",\n );\n};\n\nconst validateAccountsActionsPublishVoteArguments = ({\n publishVoteOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishVote accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishVote accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishVote no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishVoteOptions && typeof publishVoteOptions === \"object\",\n \"publishVote publishVoteOptions not an object\",\n );\n assert(\n typeof publishVoteOptions.onChallenge === \"function\",\n \"publishVote publishVoteOptions.onChallenge not a function\",\n );\n assert(\n typeof publishVoteOptions.onChallengeVerification === \"function\",\n \"publishVote publishVoteOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishVoteOptions.onError || typeof publishVoteOptions.onError === \"function\",\n \"publishVote publishVoteOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishVoteOptions) === \"string\",\n \"publishVote publishVoteOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishVoteOptions.commentCid === \"string\",\n \"publishVote publishVoteOptions.commentCid not a string\",\n );\n assert(\n publishVoteOptions.vote === 1 ||\n publishVoteOptions.vote === 0 ||\n publishVoteOptions.vote === -1,\n \"publishVote publishVoteOptions.vote not 1, 0 or -1\",\n );\n assert(\n !publishVoteOptions.timestamp || typeof publishVoteOptions.timestamp === \"number\",\n \"publishVote publishVoteOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentEditArguments = ({\n publishCommentEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentEditOptions && typeof publishCommentEditOptions === \"object\",\n \"publishCommentEdit publishCommentEditOptions not an object\",\n );\n assert(\n typeof publishCommentEditOptions.onChallenge === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentEditOptions.onChallengeVerification === \"function\",\n \"publishCommentEdit publishCommentEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentEditOptions.onError || typeof publishCommentEditOptions.onError === \"function\",\n \"publishCommentEditOptions publishCommentEditOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentEditOptions) === \"string\",\n \"publishCommentEdit publishCommentEditOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentEditOptions.commentCid === \"string\",\n \"publishCommentEdit publishCommentEditOptions.commentCid not a string\",\n );\n assert(\n !publishCommentEditOptions.timestamp || typeof publishCommentEditOptions.timestamp === \"number\",\n \"publishCommentEdit publishCommentEditOptions.timestamp is not a number\",\n );\n};\n\nconst validateAccountsActionsPublishCommentModerationArguments = ({\n publishCommentModerationOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommentModeration accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommentModeration accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommentModeration no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommentModerationOptions && typeof publishCommentModerationOptions === \"object\",\n \"publishCommentModeration publishCommentModerationOptions not an object\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallenge === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommentModerationOptions.onChallengeVerification === \"function\",\n \"publishCommentModeration publishCommentModerationOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommentModerationOptions.onError ||\n typeof publishCommentModerationOptions.onError === \"function\",\n \"publishCommentModerationOptions publishCommentModerationOptions.onError not a function\",\n );\n assert(\n typeof getPublicationCommunityAddress(publishCommentModerationOptions) === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.communityAddress/communityAddress not a string\",\n );\n assert(\n typeof publishCommentModerationOptions.commentCid === \"string\",\n \"publishCommentModeration publishCommentModerationOptions.commentCid not a string\",\n );\n assert(\n !publishCommentModerationOptions.timestamp ||\n typeof publishCommentModerationOptions.timestamp === \"number\",\n \"publishCommentModeration publishCommentModerationOptions.timestamp is not a number\",\n );\n assert(\n publishCommentModerationOptions.commentModeration &&\n typeof publishCommentModerationOptions.commentModeration === \"object\",\n \"publishCommentModeration publishCommentModerationOptions.commentModeration is not an object\",\n );\n};\n\n// communities reject a domain name with an uppercase letter, the same check as pkc-js\n// doesDomainAddressHaveCapitalLetter. public keys have no \".\" and are case-sensitive, so they are not checked\nconst assertDomainNameIsLowercase = (name: unknown, code: string, message: string) => {\n if (typeof name === \"string\" && name.includes(\".\") && /[A-Z]/.test(name)) {\n const error: Error & { code?: string } = new Error(message);\n error.code = code;\n throw error;\n }\n};\n\nconst validateCommunityNameIsLowercase = (options: any, optionsName: string) => {\n for (const field of [\"name\", \"address\"]) {\n assertDomainNameIsLowercase(\n options?.[field],\n \"ERR_COMMUNITY_NAME_HAS_CAPITAL_LETTER\",\n `${optionsName}.${field} '${options?.[field]}' has an uppercase letter, community names must be lowercase`,\n );\n }\n};\n\n// pkc-js publishes author.name, or author.address when the account stores its domain name there. only a\n// changed name is checked, so a name saved before this check does not block unrelated account edits\nconst validateAccountsActionsSetAccountAuthorName = (author: any, previousAuthor: any) => {\n for (const field of [\"name\", \"address\"]) {\n if (author?.[field] !== previousAuthor?.[field]) {\n assertDomainNameIsLowercase(\n author?.[field],\n \"ERR_AUTHOR_NAME_HAS_CAPITAL_LETTER\",\n `setAccount account.author.${field} '${author?.[field]}' has an uppercase letter, author names must be lowercase`,\n );\n }\n }\n};\n\nconst validateAccountsActionsCreateCommunityArguments = (createCommunityOptions: any) => {\n validateCommunityNameIsLowercase(\n createCommunityOptions,\n \"createCommunity createCommunityOptions\",\n );\n};\n\nconst validateAccountsActionsPublishCommunityEditArguments = ({\n communityAddress,\n publishCommunityEditOptions,\n accountName,\n account,\n}: any) => {\n assert(\n !accountName || typeof accountName === \"string\",\n `publishCommunityEdit accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `publishCommunityEdit accountName argument is empty string`);\n assert(\n !accountName || account,\n `publishCommunityEdit no account with name '${accountName}' in accountsStore`,\n );\n assert(\n publishCommunityEditOptions && typeof publishCommunityEditOptions === \"object\",\n \"publishCommunityEdit publishCommunityEditOptions not an object\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallenge === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallenge not a function\",\n );\n assert(\n typeof publishCommunityEditOptions.onChallengeVerification === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onChallengeVerification not a function\",\n );\n assert(\n !publishCommunityEditOptions.onError ||\n typeof publishCommunityEditOptions.onError === \"function\",\n \"publishCommunityEdit publishCommunityEditOptions.onError not a function\",\n );\n assert(communityAddress !== \"\", `publishCommunityEdit communityAddress argument is empty string`);\n assert(\n typeof communityAddress === \"string\",\n \"publishCommunityEdit communityAddress not a string\",\n );\n assert(\n !publishCommunityEditOptions.timestamp ||\n typeof publishCommunityEditOptions.timestamp === \"number\",\n \"publishCommunityEdit publishCommunityEditOptions.timestamp is not a number\",\n );\n validateCommunityNameIsLowercase(\n publishCommunityEditOptions,\n \"publishCommunityEdit publishCommunityEditOptions\",\n );\n};\n\nconst validateAccountsActionsExportAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `exportAccount accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `exportAccount accountName argument is empty string`);\n};\n\nconst validateAccountsActionsSetAccountsOrderArguments = (\n newOrderedAccountNames: any,\n accountNames: any,\n) => {\n assert(\n JSON.stringify([...accountNames].sort()) === JSON.stringify([...newOrderedAccountNames].sort()),\n `previous account names '${accountNames} contain different account names than argument newOrderedAccountNames '${newOrderedAccountNames}'`,\n );\n};\n\nconst validateAccountsActionsSetAccountArguments = (account: any) => {\n assert(account && typeof account === \"object\", `setAccount account '${account}' not an object`);\n assert(\n typeof account.name === \"string\",\n `setAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `setAccount account.name is empty string`);\n assert(typeof account.id === \"string\", `setAccount account.id '${account.id}' not a string`);\n assert(account.id !== \"\", `setAccount account.id is empty string`);\n};\n\nconst validateAccountsActionsSetActiveAccountArguments = (accountName: any) => {\n assert(\n typeof accountName === \"string\",\n `setActiveAccountName accountName '${accountName}' not a string`,\n );\n assert(accountName !== \"\", `setActiveAccountName accountName argument is empty string`);\n};\n\nconst validateAccountsDatabaseGetAccountsArguments = (accountIds: any) => {\n assert(\n Array.isArray(accountIds),\n `accountsDatabase.getAccounts accountIds '${accountIds}' not an array`,\n );\n assert(accountIds.length > 0, `accountsDatabase.getAccounts accountIds array is empty`);\n for (const accountId of accountIds) {\n assert(\n typeof accountId === \"string\",\n `accountsDatabase.getAccountsaccountIds '${accountIds}' accountId '${accountId}' not a string`,\n );\n assert(\n accountId !== \"\",\n `accountsDatabase.getAccounts accountIds '${accountIds}' an accountId argument is empty string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAccountNames = (accountNames: any) => {\n assert(\n Array.isArray(accountNames),\n `accountsDatabase accountNames '${accountNames}' not an array`,\n );\n for (const accountName of accountNames) {\n assert(\n typeof accountName === \"string\",\n `accountsDatabase accountNames '${accountNames}' accountName '${accountName}' not a string`,\n );\n }\n};\n\nconst validateAccountsDatabaseAddAccountArguments = (account: any) => {\n assert(\n account && typeof account === \"object\",\n `accountsDatabase.addAccount '${account}' not an object`,\n );\n assert(\n typeof account.name === \"string\",\n `accountsDatabase.addAccount account.name '${account.name}' not a string`,\n );\n assert(account.name !== \"\", `accountsDatabase.addAccount account.name is empty string`);\n assert(\n typeof account.id === \"string\",\n `accountsDatabase.addAccount account.id '${account.id}' not a string`,\n );\n assert(account.id !== \"\", `accountsDatabase.addAccount account.id is empty string`);\n};\n\nconst validateUseCommentArguments = (commentCid: any, account: any) => {\n assert(typeof commentCid === \"string\", `useComment commentCid '${commentCid}' not a string`);\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComment account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateUseCommentsArguments = (commentCids: any, account: any) => {\n assert(\n Array.isArray(commentCids),\n `useComment commentCids '${toString(commentCids)}' not an array`,\n );\n for (const commentCid of commentCids) {\n assert(\n typeof commentCid === \"string\",\n `useComments commentCids '${toString(commentCids)}' commentCid '${toString(commentCid)}' not a string`,\n );\n }\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useComments account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n};\n\nconst validateCommunityIdentifierArguments = (\n community: any,\n legacyCommunityAddress: any,\n scope: string,\n) => {\n assert(\n legacyCommunityAddress === undefined,\n `${scope} communityAddress has been removed, pass { community: { name, publicKey } }`,\n );\n if (community === undefined) {\n return;\n }\n assertCommunityRef(community, `${scope} community`);\n};\n\nconst validateUseCommunityArguments = ({ community, communityAddress, account }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunity\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateUseCommunityStatsArguments = ({ community, communityAddress }: any) => {\n validateCommunityIdentifierArguments(community, communityAddress, \"useCommunityStats\");\n};\n\nconst validateCommunitiesArguments = (\n communities: any,\n communityRefs: any,\n communityAddresses: any,\n scope: string,\n) => {\n assert(\n communityRefs === undefined,\n `${scope} communityRefs has been removed, pass communities instead`,\n );\n assert(\n communityAddresses === undefined,\n `${scope} communityAddresses has been removed, pass communities instead`,\n );\n if (communities !== undefined) {\n assert(\n Array.isArray(communities),\n `${scope} communities '${toString(communities)}' not an array`,\n );\n for (const community of communities) {\n assertCommunityRef(\n community,\n `${scope} communities '${toString(communities)}' community '${toString(community)}'`,\n );\n }\n }\n};\n\nconst validateUseCommunitiesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n account,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useCommunities\");\n if (account !== undefined && account !== null) {\n assert(\n getAccountProtocolClient(account) && typeof getAccountProtocolClient(account) === \"object\",\n `useCommunity account.pkc/account.pkc '${getAccountProtocolClient(account)}' not an object`,\n );\n }\n};\n\nconst validateFeedSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid feed sort type '${sortType}'`,\n );\n};\nconst isValidAccountCommentsLimit = (limit: any) =>\n limit === undefined || limit === null || (Number.isInteger(limit) && limit >= 0);\nconst validateUseFeedArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n includeBlockedCids,\n}: any) => {\n validateCommunitiesArguments(communities, communityRefs, communityAddresses, \"useFeed\");\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useFeed sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useFeed accountName argument '${accountName}' not a string`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useFeed postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useFeed filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useFeed filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(typeof newerThan === \"number\", `useFeed newerThan argument '${newerThan}' not a number`);\n }\n if (accountComments) {\n assert(\n typeof accountComments === \"object\",\n `useFeed accountComments argument '${accountComments}' not an object`,\n );\n assert(\n typeof accountComments.newerThan === \"number\",\n `useFeed accountComments.newerThan argument '${accountComments}' not a number`,\n );\n assert(\n isValidAccountCommentsLimit(accountComments.limit),\n `useFeed accountComments.limit argument '${accountComments.limit}' not a non-negative integer`,\n );\n }\n if (includeBlockedCids !== undefined && includeBlockedCids !== null) {\n assert(\n typeof includeBlockedCids === \"boolean\",\n `useFeed includeBlockedCids argument '${includeBlockedCids}' not a boolean`,\n );\n }\n};\nconst validateUseBufferedFeedsArguments = ({\n feedsOptions,\n accountName,\n}: {\n feedsOptions?: any;\n accountName?: any;\n}) => {\n assert(\n Array.isArray(feedsOptions),\n `useBufferedFeeds feedsOptions argument '${toString(feedsOptions)}' not an array`,\n );\n for (const {\n communities,\n communityRefs,\n communityAddresses,\n sortType,\n postsPerPage,\n filter,\n newerThan,\n } of feedsOptions) {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useBufferedFeeds feedOptions\",\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useBufferedFeeds feedOptions.sortType argument '${sortType}' invalid`,\n );\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useBufferedFeeds feedOptions.postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useBufferedFeeds feedOptions.filter.filter argument '${filter.filter}' not a function, useFeedOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useBufferedFeeds feedOptions.filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n if (newerThan !== undefined && newerThan !== null) {\n assert(\n typeof newerThan === \"number\",\n `useBufferedFeeds feedOptions.newerThan argument '${newerThan}' not a number`,\n );\n }\n }\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useBufferedFeeds accountName argument '${accountName}' not a string`,\n );\n }\n};\n\nconst validateUseCommunitiesStatesArguments = ({\n communities,\n communityRefs,\n communityAddresses,\n}: any) => {\n validateCommunitiesArguments(\n communities,\n communityRefs,\n communityAddresses,\n \"useCommunitiesStates\",\n );\n};\n\nconst validateRepliesSortType = (sortType: any) => {\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `invalid replies sort type '${sortType}'`,\n );\n};\nconst validateUseRepliesArguments = (\n comment?: any,\n sortType?: any,\n accountName?: any,\n onlyIfCached?: any,\n flat?: any,\n accountComments?: any,\n postsPerPage?: any,\n filter?: any,\n) => {\n assert(\n !comment || typeof comment === \"object\",\n `useReplies comment argument '${comment}' not an object`,\n );\n assert(\n !comment?.cid || typeof comment.cid === \"string\",\n `useReplies comment.cid argument '${comment?.cid}' not a string`,\n );\n assert(\n sortType === undefined || (typeof sortType === \"string\" && sortType.length > 0),\n `useReplies sortType argument '${sortType}' invalid`,\n );\n if (accountName) {\n assert(\n typeof accountName === \"string\",\n `useReplies accountName argument '${accountName}' not a string`,\n );\n }\n if (onlyIfCached !== undefined && onlyIfCached !== null) {\n assert(\n typeof onlyIfCached === \"boolean\",\n `useReplies onlyIfCached argument '${onlyIfCached}' not a boolean`,\n );\n }\n if (postsPerPage !== undefined && postsPerPage !== null) {\n assert(\n typeof postsPerPage === \"number\",\n `useReplies postsPerPage argument '${postsPerPage}' not a number`,\n );\n }\n if (flat !== undefined && flat !== null) {\n assert(typeof flat === \"boolean\", `useReplies flat argument '${flat}' not a boolean`);\n }\n if (accountComments !== undefined && accountComments !== null) {\n assert(\n typeof accountComments.newerThan === \"number\",\n `useReplies accountComments.newerThan argument '${accountComments.newerThan}' not a number`,\n );\n assert(\n !accountComments.append || typeof accountComments.append === \"boolean\",\n `useReplies accountComments.append argument '${accountComments.append}' not a boolean`,\n );\n assert(\n isValidAccountCommentsLimit(accountComments.limit),\n `useReplies accountComments.limit argument '${accountComments.limit}' not a non-negative integer`,\n );\n }\n if (filter) {\n assert(\n typeof filter.filter === \"function\",\n `useReplies filter.filter argument '${filter.filter}' not a function, useRepliesOptions.filter is now an object Filter {filter: (comment: Comment) => Boolean, key: string}`,\n );\n assert(\n typeof filter.key === \"string\",\n `useReplies filter.key argument '${filter.key}' not a string, a unique filter.key is now required to cache the filter`,\n );\n }\n};\n\nconst validator = {\n validateAccountsActionsPublishCommentArguments,\n validateAccountsActionsPublishCommentEditArguments,\n validateAccountsActionsPublishCommentModerationArguments,\n validateAccountsActionsPublishCommunityEditArguments,\n validateAccountsActionsCreateCommunityArguments,\n validateAccountsActionsPublishVoteArguments,\n validateAccountsActionsExportAccountArguments,\n validateAccountsActionsSetAccountsOrderArguments,\n validateAccountsActionsSetAccountArguments,\n validateAccountsActionsSetAccountAuthorName,\n validateAccountsActionsSetActiveAccountArguments,\n validateAccountsDatabaseAddAccountArguments,\n validateAccountsDatabaseGetAccountsArguments,\n validateAccountsDatabaseAccountNames,\n validateUseCommentArguments,\n validateUseCommentsArguments,\n validateUseCommunityArguments,\n validateUseCommunityStatsArguments,\n validateUseCommunitiesArguments,\n validateUseCommunitiesStatesArguments,\n validateFeedSortType,\n validateUseFeedArguments,\n validateUseBufferedFeedsArguments,\n validateRepliesSortType,\n validateUseRepliesArguments,\n};\n\nexport default validator;\n"]}
@@ -25,6 +25,7 @@ declare const accountGenerator: {
25
25
  communities: {
26
26
  [communityAddress: string]: AccountCommunity;
27
27
  };
28
+ createdAt: number;
28
29
  subscriptions: never[];
29
30
  blockedAddresses: {};
30
31
  blockedCids: {};
@@ -1 +1 @@
1
- {"version":3,"file":"account-generator.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASzE,eAAO,MAAM,mBAAmB,wCAAwC,CAAC;AACzE,eAAO,MAAM,oBAAoB,UAOhC,CAAC;AACF,eAAO,MAAM,wBAAwB,UAOpC,CAAC;AAgBF,eAAO,MAAM,mBAAmB;;;;CAI/B,CAAC;AAqBF,eAAO,MAAM,wBAAwB,QAQd,cACtB,CAAC;AAGF,eAAO,MAAM,oBAAoB;;;CAwBhC,CAAC;AAMF,eAAO,MAAM,uBAAuB;;;;;;;CAOlC,CAAC;AAsFH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"account-generator.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/account-generator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAW,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASxE,eAAO,MAAM,mBAAmB,wCAAwC,CAAC;AACzE,eAAO,MAAM,oBAAoB,UAOhC,CAAC;AACF,eAAO,MAAM,wBAAwB,UAOpC,CAAC;AAgBF,eAAO,MAAM,mBAAmB;;;;CAI/B,CAAC;AAqBF,eAAO,MAAM,wBAAwB,QAQd,cACtB,CAAC;AAGF,eAAO,MAAM,oBAAoB;;;CAwBhC,CAAC;AAMF,eAAO,MAAM,uBAAuB;;;;;;;CAOlC,CAAC;AAgGH,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -127,7 +127,11 @@ const generateDefaultAccount = () => __awaiter(void 0, void 0, void 0, function*
127
127
  const account = normalizeAccountProtocolConfig(withProtocolAliases(Object.assign(Object.assign({ id: uuid(), version: accountsDatabase.accountVersion, name: accountName, author,
128
128
  signer,
129
129
  chainProviders,
130
- pkcOptions }, getDefaultAccountFields()), { communities }), pkc, pkcOptions), chainProviders);
130
+ pkcOptions }, getDefaultAccountFields()), { communities,
131
+ // unix timestamp in seconds, like community.createdAt. Only set when an account is
132
+ // generated (not in getDefaultAccountFields): accounts created before this field existed
133
+ // and their imports keep it undefined instead of an invented date
134
+ createdAt: Math.floor(Date.now() / 1000) }), pkc, pkcOptions), chainProviders);
131
135
  return account;
132
136
  });
133
137
  const getNextAvailableDefaultAccountName = (authorAddress) => __awaiter(void 0, void 0, void 0, function* () {
@@ -137,9 +141,13 @@ const getNextAvailableDefaultAccountName = (authorAddress) => __awaiter(void 0,
137
141
  const accountIds = yield accountsDatabase.accountsMetadataDatabase.getItem("accountIds");
138
142
  const accountNames = [];
139
143
  if (accountIds === null || accountIds === void 0 ? void 0 : accountIds.length) {
140
- const accounts = yield accountsDatabase.getAccounts(accountIds);
141
- for (const accountId of accountIds) {
142
- accountNames.push(accounts[accountId].name);
144
+ // read the stored records: hydrating the accounts would create a pkc client per account that
145
+ // nothing destroys
146
+ const storedAccounts = yield Promise.all(accountIds.map((accountId) => accountsDatabase.accountsDatabase.getItem(accountId)));
147
+ for (const storedAccount of storedAccounts) {
148
+ if (storedAccount) {
149
+ accountNames.push(storedAccount.name);
150
+ }
143
151
  }
144
152
  }
145
153
  if (!(accountNames === null || accountNames === void 0 ? void 0 : accountNames.length)) {