@bitsocial/bitsocial-react-hooks 0.2.6 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -1
- package/dist/hooks/accounts/accounts.js +33 -6
- package/dist/hooks/accounts/accounts.js.map +1 -1
- package/dist/hooks/actions/actions.d.ts.map +1 -1
- package/dist/hooks/actions/actions.js +1 -1
- package/dist/hooks/actions/actions.js.map +1 -1
- package/dist/hooks/comments.d.ts.map +1 -1
- package/dist/hooks/comments.js +47 -11
- package/dist/hooks/comments.js.map +1 -1
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +9 -2
- package/dist/hooks/communities.js.map +1 -1
- package/dist/hooks/feeds/feeds.d.ts.map +1 -1
- package/dist/hooks/feeds/feeds.js +27 -2
- package/dist/hooks/feeds/feeds.js.map +1 -1
- package/dist/lib/community-ref.d.ts +3 -0
- package/dist/lib/community-ref.d.ts.map +1 -1
- package/dist/lib/community-ref.js +2 -0
- package/dist/lib/community-ref.js.map +1 -1
- package/dist/lib/pkc-compat.d.ts +19 -5
- package/dist/lib/pkc-compat.d.ts.map +1 -1
- package/dist/lib/pkc-compat.js +49 -10
- package/dist/lib/pkc-compat.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock-content.js +5 -4
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +3 -2
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.js +11 -2
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +5 -5
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/comments/comments-store.d.ts +3 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -1
- package/dist/stores/comments/comments-store.js +26 -0
- package/dist/stores/comments/comments-store.js.map +1 -1
- package/dist/stores/communities/communities-store.d.ts +4 -1
- package/dist/stores/communities/communities-store.d.ts.map +1 -1
- package/dist/stores/communities/communities-store.js +51 -7
- package/dist/stores/communities/communities-store.js.map +1 -1
- package/dist/stores/feeds/utils.d.ts.map +1 -1
- package/dist/stores/feeds/utils.js +2 -5
- package/dist/stores/feeds/utils.js.map +1 -1
- package/dist/types.d.ts +40 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,mCAAmC,CAAC,CAAC;AACxD,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAUtC,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAC/C,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAEL,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,IAAI,+BAA+B,GAAG,CAAC,CAAC;AACxC,MAAM,WAAW,GAAY,EAAE,CAAC;AA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AAC,GAAG,EAAE;;QAClB,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YACtC,SAAS,CAAC,IAAI,CACZ,gBAAgB,CAAC;gBACf,SAAS;gBACT,SAAS,CAAC,CAAC,CAAC;gBACZ,yBAAyB,CAAC,CAAC,CAAC;gBAC5B,aAAa,CAAC,CAAC,CAAC;gBAChB,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,GAAG;gBACf,UAAU,CAAC,CAAC,CAAC;aACd,CAAC,CACH,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,yBAAyB,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useAccount } from \"../accounts\";\nimport validator from \"../../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:hooks\");\nimport assert from \"../../lib/assert\";\nimport {\n Feed,\n Feeds,\n UseBufferedFeedsOptions,\n UseBufferedFeedsResult,\n UseFeedOptions,\n UseFeedResult,\n CommentsFilter,\n} from \"../../types\";\nimport useFeedsStore from \"../../stores/feeds\";\nimport useAccountsStore from \"../../stores/accounts\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport { addOptimisticVoteCountsToComments } from \"../../lib/utils/optimistic-vote-counts\";\nimport shallow from \"zustand/shallow\";\nimport {\n CommunityLookupRef,\n getCommunityRefKeys,\n getUniqueSortedCommunityRefs,\n} from \"../../lib/community-ref\";\nimport { serializeFeedKey } from \"../../lib/serialize-feed-key\";\n\nlet feedAutoUpdateSubscriptionCount = 0;\nconst emptyErrors: Error[] = [];\nconst emptyCommunityKeys: string[] = [];\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param sortType - A sort name published by the community, or a standard sort computed client-side\n * when every post fits in the preloaded page. Omit it to use the preloaded sort.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useFeed(options?: UseFeedOptions): UseFeedResult {\n assert(\n !options || typeof options === \"object\",\n `useFeed options argument '${options}' not an object`,\n );\n const opts = options || {};\n let {\n communities,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n includeBlockedCids,\n } = opts;\n validator.validateUseFeedArguments({\n communities,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n includeBlockedCids,\n });\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useFeed-${++feedAutoUpdateSubscriptionCount}`);\n const incrementFeedPageNumber = useFeedsStore((state) => state.incrementFeedPageNumber);\n const expandFeedTimeWindow = useFeedsStore((state) => state.expandFeedTimeWindow);\n const resetFeed = useFeedsStore((state) => state.resetFeed);\n const normalizedCommunityRefs = useMemo(() => communities || [], [communities]);\n const uniqueCommunityRefs = useUniqueSortedCommunityRefs(normalizedCommunityRefs);\n const uniqueCommunityKeys = useMemo(\n () => getCommunityRefKeys(uniqueCommunityRefs),\n [uniqueCommunityRefs],\n );\n const feedName = useFeedName(\n account?.id,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n includeBlockedCids,\n );\n // errors belong to the feed they happened in, another feed starts without them. Drop them when\n // the feed changes (or when one lands after it changed) so they don't return with the old feed\n const [feedErrors, setFeedErrors] = useState<{ feedName: string; errors: Error[] }>();\n if (feedErrors && feedErrors.feedName !== feedName) {\n setFeedErrors(undefined);\n }\n const errors = feedErrors?.feedName === feedName ? feedErrors.errors : emptyErrors;\n const addError = (error: Error) =>\n setFeedErrors((previous) => ({\n feedName,\n errors: previous?.feedName === feedName ? [...previous.errors, error] : [error],\n }));\n const communityKeysWithNewerPosts = useFeedsStore(\n (state) => state.feedsCommunityKeysWithNewerPosts[feedName],\n );\n const feedCommunityKeysWithMore = useFeedsStore(\n (state) => state.feedsCommunityKeysWithMore[feedName],\n );\n const communityKeysWithUnavailableSort = useFeedsStore(\n (state) => state.feedsCommunityKeysWithUnavailableSort[feedName],\n );\n\n // add feed to store\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const isBufferedFeed = false;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n includeBlockedCids,\n ).catch((error: unknown) => log.error(\"useFeed addFeedToStore error\", { feedName, error }));\n }, [feedName]);\n\n // keep the feed's communities updating while mounted, after the feed was added above\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n startFeedAutoUpdate(feedName, subscriberId);\n return () => stopFeedAutoUpdate(feedName, subscriberId);\n }, [feedName]);\n\n const feedKey = feedName;\n const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);\n const updatedFeed = useFeedsStore((state) => state.updatedFeeds[feedKey]);\n const bufferedFeed = useFeedsStore((state) => state.bufferedFeeds[feedKey]);\n let hasMore = useFeedsStore((state) => state.feedsHaveMore[feedKey]);\n if (!feedName || typeof hasMore !== \"boolean\") {\n hasMore = true;\n }\n if (!normalizedCommunityRefs.length) {\n hasMore = false;\n }\n\n const loadMore = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot load more feed not initalized yet\");\n }\n try {\n incrementFeedPageNumber(feedName);\n } catch (error) {\n // infinite scroll calls loadMore before the feed or its current page has loaded, the\n // store refuses the page increment and that isn't a feed error\n log(\"useFeed loadMore before the feed page loaded\", { feedName, error });\n await new Promise((r) => setTimeout(r, 50));\n }\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n addError(e);\n }\n };\n\n const reset = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot reset feed not initalized yet\");\n }\n await resetFeed(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n addError(e);\n }\n };\n\n const expandTimeWindow = async (nextNewerThan?: number) => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot expand time window before feed initialized yet\");\n }\n expandFeedTimeWindow(feedName, nextNewerThan);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n addError(e);\n }\n };\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useFeed\", {\n feedLength: feed?.length || 0,\n hasMore,\n communities: normalizedCommunityRefs,\n communityKeys: uniqueCommunityKeys,\n sortType,\n account,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = !hasMore ? \"succeeded\" : \"fetching-ipns\";\n // until the feed is first calculated, every community still has more\n let communityKeysWithMore = feedCommunityKeysWithMore || uniqueCommunityKeys;\n if (!normalizedCommunityRefs.length) {\n communityKeysWithMore = [];\n }\n // apply the account's pending votes like useComment/useComments/useReplies do, so voting from a\n // feed updates the score immediately instead of only once the community publishes the new counts\n const normalizedFeed = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(feed), accountVotes),\n [feed, accountVotes],\n );\n const normalizedBufferedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(bufferedFeed), accountVotes),\n [bufferedFeed, accountVotes],\n );\n const normalizedUpdatedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(updatedFeed), accountVotes),\n [updatedFeed, accountVotes],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n communityKeysWithMore,\n communityKeysWithUnavailableSort: communityKeysWithUnavailableSort || emptyCommunityKeys,\n loadMore,\n expandTimeWindow,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedFeed,\n normalizedBufferedFeed,\n normalizedUpdatedFeed,\n feedName,\n hasMore,\n errors,\n communityKeysWithNewerPosts,\n communityKeysWithMore,\n communityKeysWithUnavailableSort,\n ],\n );\n}\n\n/**\n * Use useBufferedFeeds to buffer multiple feeds in the background so what when\n * they are called by useFeed later, they are already preloaded.\n *\n * @param feedOptions - The options of the feed\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useBufferedFeeds(options?: UseBufferedFeedsOptions): UseBufferedFeedsResult {\n assert(\n !options || typeof options === \"object\",\n `useBufferedFeeds options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { feedsOptions = [], accountName } = opts;\n validator.validateUseBufferedFeedsArguments({ feedsOptions, accountName });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useBufferedFeeds-${++feedAutoUpdateSubscriptionCount}`);\n\n // do a bunch of calculations to get feedsOptionsFlattened and feedNames\n const feedsOpts = feedsOptions;\n const {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n } = useMemo(() => {\n const communityRefsArrays: CommunityLookupRef[][] = [];\n const communityKeysArrays: string[][] = [];\n const sortTypes: (string | undefined)[] = [];\n const postsPerPages: (number | undefined)[] = [];\n const filters: (CommentsFilter | undefined)[] = [];\n const newerThans: (number | undefined)[] = [];\n for (const feedOptions of feedsOpts) {\n validator.validateUseFeedArguments({\n communities: feedOptions.communities,\n communityRefs: (feedOptions as any).communityRefs,\n communityAddresses: (feedOptions as any).communityAddresses,\n sortType: feedOptions.sortType,\n accountName,\n postsPerPage: feedOptions.postsPerPage,\n filter: feedOptions.filter,\n newerThan: feedOptions.newerThan,\n accountComments: feedOptions.accountComments,\n });\n const normalizedCommunityRefs = getUniqueSortedCommunityRefs(feedOptions.communities || []);\n communityRefsArrays.push(normalizedCommunityRefs);\n communityKeysArrays.push(getCommunityRefKeys(normalizedCommunityRefs));\n sortTypes.push(feedOptions.sortType);\n postsPerPages.push(feedOptions.postsPerPage);\n filters.push(feedOptions.filter);\n newerThans.push(feedOptions.newerThan);\n }\n return {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n };\n }, [feedsOpts]);\n const feedNames = useFeedNames(\n account?.id,\n sortTypes,\n communityKeysArrays,\n postsPerPages,\n filters,\n newerThans,\n );\n\n const bufferedFeeds = useFeedsStore((state) => {\n const bufferedFeeds: Feeds = {};\n for (const feedName of feedNames) {\n bufferedFeeds[feedName] = state.bufferedFeeds[feedName];\n }\n return bufferedFeeds;\n }, shallow);\n\n // add feed to store\n useEffect(() => {\n for (const [i] of communityRefsArrays.entries()) {\n const sortType = sortTypes[i];\n const uniqueCommunityRefs = communityRefsArrays[i];\n const uniqueCommunityKeys = communityKeysArrays[i];\n validator.validateFeedSortType(sortType);\n const feedName = feedNames[i];\n if (!account || !uniqueCommunityRefs.length) {\n continue;\n }\n if (!bufferedFeeds[feedName]) {\n const isBufferedFeed = true;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n ).catch((error: unknown) =>\n log.error(\"useBufferedFeeds addFeedToStore error\", { feedName, error }),\n );\n }\n }\n }, [feedNames]);\n\n // keep the buffered feeds' communities updating while mounted, keyed by the names so\n // inline options recreated on every render do not resubscribe\n useEffect(() => {\n if (!account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n const subscribedFeedNames = feedNames.filter((_, i) => communityRefsArrays[i]?.length);\n for (const feedName of subscribedFeedNames) {\n startFeedAutoUpdate(feedName, subscriberId);\n }\n return () => {\n for (const feedName of subscribedFeedNames) {\n stopFeedAutoUpdate(feedName, subscriberId);\n }\n };\n }, [JSON.stringify(feedNames), account?.id]);\n\n // only give to the user the buffered feeds he requested\n const bufferedFeedsArray: Feed[] = useMemo(() => {\n const bufferedFeedsArray: Feed[] = [];\n for (const feedName of feedNames) {\n bufferedFeedsArray.push(addCommentModerationToComments(bufferedFeeds[feedName]));\n }\n return bufferedFeedsArray;\n }, [bufferedFeeds, feedNames]);\n\n if (account && feedsOptions?.length) {\n log(\"useBufferedFeeds\", {\n bufferedFeeds,\n feedsOptions,\n account,\n accountName,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = \"fetching-ipns\";\n\n return useMemo(\n () => ({\n bufferedFeeds: bufferedFeedsArray,\n state,\n error: undefined,\n errors: [],\n }),\n [bufferedFeedsArray, feedsOptions],\n );\n}\n\nfunction useUniqueSortedCommunityRefs(communityRefs?: CommunityLookupRef[]) {\n return useMemo(() => {\n return getUniqueSortedCommunityRefs(communityRefs);\n }, [communityRefs]);\n}\n\nfunction useFeedName(\n accountId: string,\n sortType: string | undefined,\n uniqueCommunityKeys: string[],\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: UseFeedOptions[\"accountComments\"],\n modQueue?: string[],\n includeBlockedCids?: boolean,\n) {\n const filterKey = filter?.key;\n const accountCommentsNewerThan = accountComments?.newerThan;\n const accountCommentsAppend = accountComments?.append;\n const accountCommentsLimit = accountComments?.limit ?? undefined;\n return useMemo(() => {\n const feedKey: unknown[] = [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue,\n ];\n // options added later are only part of the name when set, feeds without them keep their name\n if (accountCommentsLimit !== undefined) {\n feedKey.push(accountCommentsLimit);\n }\n if (includeBlockedCids === true) {\n feedKey.push(includeBlockedCids);\n }\n return serializeFeedKey(feedKey);\n }, [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n accountCommentsLimit,\n modQueue?.toString(),\n includeBlockedCids,\n ]);\n}\n\nfunction useFeedNames(\n accountId: string,\n sortTypes: (string | undefined)[],\n uniqueCommunityKeysArrays: string[][],\n postsPerPages: (number | undefined)[],\n filters: (CommentsFilter | undefined)[],\n newerThans: (number | undefined)[],\n) {\n return useMemo(() => {\n const feedNames: string[] = [];\n for (const [i] of sortTypes.entries()) {\n feedNames.push(\n serializeFeedKey([\n accountId,\n sortTypes[i],\n uniqueCommunityKeysArrays[i],\n postsPerPages[i],\n filters[i]?.key,\n newerThans[i],\n ]),\n );\n }\n return feedNames;\n }, [accountId, sortTypes, uniqueCommunityKeysArrays, postsPerPages, filters, newerThans]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"feeds.js","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,SAAS,MAAM,qBAAqB,CAAC;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AAC,OAAO,CAAC,CAAC;IACnC,CAAC,EAAE;QACD,SAAS;QACT,QAAQ;QACR,mBAAmB;QACnB,YAAY;QACZ,SAAS;QACT,SAAS;QACT,wBAAwB;QACxB,qBAAqB;QACrB,oBAAoB;QACpB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,EAAE;QACpB,kBAAkB;KACnB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CACnB,SAAiB,EACjB,SAAiC,EACjC,yBAAqC,EACrC,aAAqC,EACrC,OAAuC,EACvC,UAAkC;IAElC,OAAO,OAAO,CAAC,GAAG,EAAE;;QAClB,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YACtC,SAAS,CAAC,IAAI,CACZ,gBAAgB,CAAC;gBACf,SAAS;gBACT,SAAS,CAAC,CAAC,CAAC;gBACZ,yBAAyB,CAAC,CAAC,CAAC;gBAC5B,aAAa,CAAC,CAAC,CAAC;gBAChB,MAAA,OAAO,CAAC,CAAC,CAAC,0CAAE,GAAG;gBACf,UAAU,CAAC,CAAC,CAAC;aACd,CAAC,CACH,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,yBAAyB,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAC5F,CAAC","sourcesContent":["import { useEffect, useMemo, useRef, useState } from \"react\";\nimport { useAccount } from \"../accounts\";\nimport validator from \"../../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:feeds:hooks\");\nimport assert from \"../../lib/assert\";\nimport {\n Feed,\n Feeds,\n UseBufferedFeedsOptions,\n UseBufferedFeedsResult,\n UseFeedOptions,\n UseFeedResult,\n CommentsFilter,\n} from \"../../types\";\nimport useFeedsStore from \"../../stores/feeds\";\nimport useCommunitiesStore, { getCommunityFirstLoadFailure } from \"../../stores/communities\";\nimport useAccountsStore from \"../../stores/accounts\";\nimport { addCommentModerationToComments } from \"../../lib/utils/comment-moderation\";\nimport { addOptimisticVoteCountsToComments } from \"../../lib/utils/optimistic-vote-counts\";\nimport shallow from \"zustand/shallow\";\nimport {\n CommunityLookupRef,\n getCommunityRefKeys,\n getUniqueSortedCommunityRefs,\n isCommunityRefBlocked,\n} from \"../../lib/community-ref\";\nimport { serializeFeedKey } from \"../../lib/serialize-feed-key\";\n\nlet feedAutoUpdateSubscriptionCount = 0;\nconst emptyErrors: Error[] = [];\nconst emptyCommunityKeys: string[] = [];\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param sortType - A sort name published by the community, or a standard sort computed client-side\n * when every post fits in the preloaded page. Omit it to use the preloaded sort.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useFeed(options?: UseFeedOptions): UseFeedResult {\n assert(\n !options || typeof options === \"object\",\n `useFeed options argument '${options}' not an object`,\n );\n const opts = options || {};\n let {\n communities,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n includeBlockedCids,\n } = opts;\n validator.validateUseFeedArguments({\n communities,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n sortType,\n accountName,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n includeBlockedCids,\n });\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useFeed-${++feedAutoUpdateSubscriptionCount}`);\n const incrementFeedPageNumber = useFeedsStore((state) => state.incrementFeedPageNumber);\n const expandFeedTimeWindow = useFeedsStore((state) => state.expandFeedTimeWindow);\n const resetFeed = useFeedsStore((state) => state.resetFeed);\n const normalizedCommunityRefs = useMemo(() => communities || [], [communities]);\n const uniqueCommunityRefs = useUniqueSortedCommunityRefs(normalizedCommunityRefs);\n const uniqueCommunityKeys = useMemo(\n () => getCommunityRefKeys(uniqueCommunityRefs),\n [uniqueCommunityRefs],\n );\n const feedName = useFeedName(\n account?.id,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n includeBlockedCids,\n );\n // errors belong to the feed they happened in, another feed starts without them. Drop them when\n // the feed changes (or when one lands after it changed) so they don't return with the old feed\n const [feedErrors, setFeedErrors] = useState<{ feedName: string; errors: Error[] }>();\n if (feedErrors && feedErrors.feedName !== feedName) {\n setFeedErrors(undefined);\n }\n const errors = feedErrors?.feedName === feedName ? feedErrors.errors : emptyErrors;\n const addError = (error: Error) =>\n setFeedErrors((previous) => ({\n feedName,\n errors: previous?.feedName === feedName ? [...previous.errors, error] : [error],\n }));\n const communityKeysWithNewerPosts = useFeedsStore(\n (state) => state.feedsCommunityKeysWithNewerPosts[feedName],\n );\n const feedCommunityKeysWithMore = useFeedsStore(\n (state) => state.feedsCommunityKeysWithMore[feedName],\n );\n const communityKeysWithUnavailableSort = useFeedsStore(\n (state) => state.feedsCommunityKeysWithUnavailableSort[feedName],\n );\n\n // add feed to store\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const isBufferedFeed = false;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n postsPerPage,\n filter,\n newerThan,\n accountComments,\n modQueue,\n includeBlockedCids,\n ).catch((error: unknown) => log.error(\"useFeed addFeedToStore error\", { feedName, error }));\n }, [feedName]);\n\n // keep the feed's communities updating while mounted, after the feed was added above\n useEffect(() => {\n if (!uniqueCommunityRefs.length || !account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n startFeedAutoUpdate(feedName, subscriberId);\n return () => stopFeedAutoUpdate(feedName, subscriberId);\n }, [feedName]);\n\n const feedKey = feedName;\n const feed = useFeedsStore((state) => state.loadedFeeds[feedKey]);\n const updatedFeed = useFeedsStore((state) => state.updatedFeeds[feedKey]);\n const bufferedFeed = useFeedsStore((state) => state.bufferedFeeds[feedKey]);\n let hasMore = useFeedsStore((state) => state.feedsHaveMore[feedKey]);\n if (!feedName || typeof hasMore !== \"boolean\") {\n hasMore = true;\n }\n if (!normalizedCommunityRefs.length) {\n hasMore = false;\n }\n\n const loadMore = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot load more feed not initalized yet\");\n }\n try {\n incrementFeedPageNumber(feedName);\n } catch (error) {\n // infinite scroll calls loadMore before the feed or its current page has loaded, the\n // store refuses the page increment and that isn't a feed error\n log(\"useFeed loadMore before the feed page loaded\", { feedName, error });\n await new Promise((r) => setTimeout(r, 50));\n }\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n addError(e);\n }\n };\n\n const reset = async () => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot reset feed not initalized yet\");\n }\n await resetFeed(feedName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n addError(e);\n }\n };\n\n const expandTimeWindow = async (nextNewerThan?: number) => {\n try {\n if (!uniqueCommunityRefs.length || !account) {\n throw Error(\"useFeed cannot expand time window before feed initialized yet\");\n }\n expandFeedTimeWindow(feedName, nextNewerThan);\n } catch (e: any) {\n await new Promise((r) => setTimeout(r, 50));\n addError(e);\n }\n };\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useFeed\", {\n feedLength: feed?.length || 0,\n hasMore,\n communities: normalizedCommunityRefs,\n communityKeys: uniqueCommunityKeys,\n sortType,\n account,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n // until the feed is first calculated, every community still has more\n let communityKeysWithMore = feedCommunityKeysWithMore || uniqueCommunityKeys;\n if (!normalizedCommunityRefs.length) {\n communityKeysWithMore = [];\n }\n // every community of the feed that isn't blocked failed to load a record with a non-retriable\n // failure, which makes useCommunity().state \"failed\". A community that is retrying, still loading\n // or has a record may still add posts.\n const blockedAddresses = account?.blockedAddresses;\n const communitiesFailedToLoad = useCommunitiesStore((state) => {\n let hasUnblockedCommunity = false;\n for (const [index, communityKey] of uniqueCommunityKeys.entries()) {\n const community = state.communities[communityKey];\n if (isCommunityRefBlocked(blockedAddresses, uniqueCommunityRefs[index], community)) {\n continue;\n }\n const syncStatus = state.syncStatuses[communityKey];\n if (getCommunityFirstLoadFailure(syncStatus, community) !== \"non-retriable\") {\n return false;\n }\n hasUnblockedCommunity = true;\n }\n return hasUnblockedCommunity;\n });\n let state = !hasMore ? \"succeeded\" : \"fetching-ipns\";\n // an empty feed that can't get posts from any of its communities\n if (hasMore && !feed?.length && communitiesFailedToLoad) {\n state = \"failed\";\n }\n // apply the account's pending votes like useComment/useComments/useReplies do, so voting from a\n // feed updates the score immediately instead of only once the community publishes the new counts\n const normalizedFeed = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(feed), accountVotes),\n [feed, accountVotes],\n );\n const normalizedBufferedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(bufferedFeed), accountVotes),\n [bufferedFeed, accountVotes],\n );\n const normalizedUpdatedFeed = useMemo(\n () =>\n addOptimisticVoteCountsToComments(addCommentModerationToComments(updatedFeed), accountVotes),\n [updatedFeed, accountVotes],\n );\n\n return useMemo(\n () => ({\n feed: normalizedFeed,\n bufferedFeed: normalizedBufferedFeed,\n updatedFeed: normalizedUpdatedFeed,\n hasMore,\n communityKeysWithNewerPosts: communityKeysWithNewerPosts || [],\n communityKeysWithMore,\n communityKeysWithUnavailableSort: communityKeysWithUnavailableSort || emptyCommunityKeys,\n loadMore,\n expandTimeWindow,\n reset,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [\n normalizedFeed,\n normalizedBufferedFeed,\n normalizedUpdatedFeed,\n feedName,\n hasMore,\n state,\n errors,\n communityKeysWithNewerPosts,\n communityKeysWithMore,\n communityKeysWithUnavailableSort,\n ],\n );\n}\n\n/**\n * Use useBufferedFeeds to buffer multiple feeds in the background so what when\n * they are called by useFeed later, they are already preloaded.\n *\n * @param feedOptions - The options of the feed\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useBufferedFeeds(options?: UseBufferedFeedsOptions): UseBufferedFeedsResult {\n assert(\n !options || typeof options === \"object\",\n `useBufferedFeeds options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { feedsOptions = [], accountName } = opts;\n validator.validateUseBufferedFeedsArguments({ feedsOptions, accountName });\n const account = useAccount({ accountName });\n const addFeedToStore = useFeedsStore((state) => state.addFeedToStore);\n const startFeedAutoUpdate = useFeedsStore((state) => state.startFeedAutoUpdate);\n const stopFeedAutoUpdate = useFeedsStore((state) => state.stopFeedAutoUpdate);\n const autoUpdateSubscriptionId = useRef(`useBufferedFeeds-${++feedAutoUpdateSubscriptionCount}`);\n\n // do a bunch of calculations to get feedsOptionsFlattened and feedNames\n const feedsOpts = feedsOptions;\n const {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n } = useMemo(() => {\n const communityRefsArrays: CommunityLookupRef[][] = [];\n const communityKeysArrays: string[][] = [];\n const sortTypes: (string | undefined)[] = [];\n const postsPerPages: (number | undefined)[] = [];\n const filters: (CommentsFilter | undefined)[] = [];\n const newerThans: (number | undefined)[] = [];\n for (const feedOptions of feedsOpts) {\n validator.validateUseFeedArguments({\n communities: feedOptions.communities,\n communityRefs: (feedOptions as any).communityRefs,\n communityAddresses: (feedOptions as any).communityAddresses,\n sortType: feedOptions.sortType,\n accountName,\n postsPerPage: feedOptions.postsPerPage,\n filter: feedOptions.filter,\n newerThan: feedOptions.newerThan,\n accountComments: feedOptions.accountComments,\n });\n const normalizedCommunityRefs = getUniqueSortedCommunityRefs(feedOptions.communities || []);\n communityRefsArrays.push(normalizedCommunityRefs);\n communityKeysArrays.push(getCommunityRefKeys(normalizedCommunityRefs));\n sortTypes.push(feedOptions.sortType);\n postsPerPages.push(feedOptions.postsPerPage);\n filters.push(feedOptions.filter);\n newerThans.push(feedOptions.newerThan);\n }\n return {\n communityRefsArrays,\n communityKeysArrays,\n sortTypes,\n postsPerPages,\n filters,\n newerThans,\n };\n }, [feedsOpts]);\n const feedNames = useFeedNames(\n account?.id,\n sortTypes,\n communityKeysArrays,\n postsPerPages,\n filters,\n newerThans,\n );\n\n const bufferedFeeds = useFeedsStore((state) => {\n const bufferedFeeds: Feeds = {};\n for (const feedName of feedNames) {\n bufferedFeeds[feedName] = state.bufferedFeeds[feedName];\n }\n return bufferedFeeds;\n }, shallow);\n\n // add feed to store\n useEffect(() => {\n for (const [i] of communityRefsArrays.entries()) {\n const sortType = sortTypes[i];\n const uniqueCommunityRefs = communityRefsArrays[i];\n const uniqueCommunityKeys = communityKeysArrays[i];\n validator.validateFeedSortType(sortType);\n const feedName = feedNames[i];\n if (!account || !uniqueCommunityRefs.length) {\n continue;\n }\n if (!bufferedFeeds[feedName]) {\n const isBufferedFeed = true;\n addFeedToStore(\n feedName,\n uniqueCommunityRefs,\n uniqueCommunityKeys,\n sortType,\n account,\n isBufferedFeed,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n ).catch((error: unknown) =>\n log.error(\"useBufferedFeeds addFeedToStore error\", { feedName, error }),\n );\n }\n }\n }, [feedNames]);\n\n // keep the buffered feeds' communities updating while mounted, keyed by the names so\n // inline options recreated on every render do not resubscribe\n useEffect(() => {\n if (!account) {\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n const subscribedFeedNames = feedNames.filter((_, i) => communityRefsArrays[i]?.length);\n for (const feedName of subscribedFeedNames) {\n startFeedAutoUpdate(feedName, subscriberId);\n }\n return () => {\n for (const feedName of subscribedFeedNames) {\n stopFeedAutoUpdate(feedName, subscriberId);\n }\n };\n }, [JSON.stringify(feedNames), account?.id]);\n\n // only give to the user the buffered feeds he requested\n const bufferedFeedsArray: Feed[] = useMemo(() => {\n const bufferedFeedsArray: Feed[] = [];\n for (const feedName of feedNames) {\n bufferedFeedsArray.push(addCommentModerationToComments(bufferedFeeds[feedName]));\n }\n return bufferedFeedsArray;\n }, [bufferedFeeds, feedNames]);\n\n if (account && feedsOptions?.length) {\n log(\"useBufferedFeeds\", {\n bufferedFeeds,\n feedsOptions,\n account,\n accountName,\n feedsStoreOptions: useFeedsStore.getState().feedsOptions,\n feedsStore: useFeedsStore.getState(),\n });\n }\n\n const state = \"fetching-ipns\";\n\n return useMemo(\n () => ({\n bufferedFeeds: bufferedFeedsArray,\n state,\n error: undefined,\n errors: [],\n }),\n [bufferedFeedsArray, feedsOptions],\n );\n}\n\nfunction useUniqueSortedCommunityRefs(communityRefs?: CommunityLookupRef[]) {\n return useMemo(() => {\n return getUniqueSortedCommunityRefs(communityRefs);\n }, [communityRefs]);\n}\n\nfunction useFeedName(\n accountId: string,\n sortType: string | undefined,\n uniqueCommunityKeys: string[],\n postsPerPage?: number,\n filter?: CommentsFilter,\n newerThan?: number,\n accountComments?: UseFeedOptions[\"accountComments\"],\n modQueue?: string[],\n includeBlockedCids?: boolean,\n) {\n const filterKey = filter?.key;\n const accountCommentsNewerThan = accountComments?.newerThan;\n const accountCommentsAppend = accountComments?.append;\n const accountCommentsLimit = accountComments?.limit ?? undefined;\n return useMemo(() => {\n const feedKey: unknown[] = [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n modQueue,\n ];\n // options added later are only part of the name when set, feeds without them keep their name\n if (accountCommentsLimit !== undefined) {\n feedKey.push(accountCommentsLimit);\n }\n if (includeBlockedCids === true) {\n feedKey.push(includeBlockedCids);\n }\n return serializeFeedKey(feedKey);\n }, [\n accountId,\n sortType,\n uniqueCommunityKeys,\n postsPerPage,\n filterKey,\n newerThan,\n accountCommentsNewerThan,\n accountCommentsAppend,\n accountCommentsLimit,\n modQueue?.toString(),\n includeBlockedCids,\n ]);\n}\n\nfunction useFeedNames(\n accountId: string,\n sortTypes: (string | undefined)[],\n uniqueCommunityKeysArrays: string[][],\n postsPerPages: (number | undefined)[],\n filters: (CommentsFilter | undefined)[],\n newerThans: (number | undefined)[],\n) {\n return useMemo(() => {\n const feedNames: string[] = [];\n for (const [i] of sortTypes.entries()) {\n feedNames.push(\n serializeFeedKey([\n accountId,\n sortTypes[i],\n uniqueCommunityKeysArrays[i],\n postsPerPages[i],\n filters[i]?.key,\n newerThans[i],\n ]),\n );\n }\n return feedNames;\n }, [accountId, sortTypes, uniqueCommunityKeysArrays, postsPerPages, filters, newerThans]);\n}\n"]}
|
|
@@ -18,6 +18,9 @@ export declare const getUniqueSortedCommunityRefs: (communityRefs?: CommunityLoo
|
|
|
18
18
|
export declare const isCommunityRef: (value: unknown) => value is CommunityLookupRef;
|
|
19
19
|
export declare function assertCommunityRef(value: unknown, label: string): asserts value is CommunityLookupRef;
|
|
20
20
|
export declare const doesAddressMatchCommunityRef: (communityAddress: string | undefined, communityRef: CommunityLookupRef, community?: Community) => boolean;
|
|
21
|
+
export declare const isCommunityRefBlocked: (blockedAddresses: {
|
|
22
|
+
[address: string]: unknown;
|
|
23
|
+
} | undefined, communityRef: CommunityLookupRef | undefined, community?: Community) => boolean;
|
|
21
24
|
export declare const getMatchingCommunityRefKeys: (communityRefs: CommunityLookupRef[], communityAddress: string | undefined, community?: Community) => string[];
|
|
22
25
|
export {};
|
|
23
26
|
//# sourceMappingURL=community-ref.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"community-ref.d.ts","sourceRoot":"","sources":["../../src/lib/community-ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG1D,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,GAAG,kBAAkB,CAAC;AAK1E,eAAO,MAAM,kBAAkB,GAAI,cAAc,kBAAkB,KAAG,MAKrE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,eAAe,kBAAkB,EAAE,aAChC,CAAC;AAExC,eAAO,MAAM,yBAAyB,GAAI,uBAAuB,kBAAkB,GAAG,MAAM;WAUlE,MAAM;gBAAc,MAAM;;;CAQnD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,MAAM,kBAAkB,EACxB,OAAO,kBAAkB,KACxB,kBAmBF,CAAC;AAEF,eAAO,MAAM,4BAA4B,GAAI,gBAAgB,kBAAkB,EAAE,yBAahF,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,kBAYxD,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,KAAK,IAAI,kBAAkB,CAErC;AAED,eAAO,MAAM,4BAA4B,GACvC,kBAAkB,MAAM,GAAG,SAAS,EACpC,cAAc,kBAAkB,EAChC,YAAY,SAAS,YAyCtB,CAAC;
|
|
1
|
+
{"version":3,"file":"community-ref.d.ts","sourceRoot":"","sources":["../../src/lib/community-ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG1D,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,MAAM,CAA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101
101
|
};
|
|
102
|
+
// whether an account's blocked addresses block a community, as feeds leave it out
|
|
103
|
+
export const isCommunityRefBlocked = (blockedAddresses, communityRef, community) => Object.keys(blockedAddresses || {}).some((blockedAddress) => communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community));
|
|
102
104
|
export const getMatchingCommunityRefKeys = (communityRefs, communityAddress, community) => {
|
|
103
105
|
const matchingCommunityKeys = new Set();
|
|
104
106
|
for (const communityRef of communityRefs) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"community-ref.js","sourceRoot":"","sources":["../../src/lib/community-ref.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AAUtE,MAAM,yBAAyB,GAAG,CAAC,YAAgC,EAAE,EAAE,CACpE,YAAmC,CAAC,OAAO,CAAC;AAE/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAAgC,EAAU,EAAE;IAC7E,MAAM,YAAY,GAChB,YAAY,CAAC,SAAS,IAAI,yBAAyB,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC;IACzF,MAAM,CAAC,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,2BAA2B,CAAC,CAAC;IACjG,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,aAAmC,EAAE,EAAE,CACzE,aAAa,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,qBAAkD,EAAE,EAAE;IAC9F,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,sBAAsB,GAAG,yBAAyB,CAAC,qBAAq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I,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM,oBAAoB,GAAG,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,EAAE,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,CAAC,CAAC;IACzF,KAAK,MAAM,UAAU,IAAI,oBAAoB,EAAE,CAAC;QAC9C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,SAAS;QACX,CAAC;QACD,IAAI,gBAAgB,KAAK,UAAU,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,+BAA+B,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,CAAC;YAClE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,aAAmC,EACnC,gBAAoC,EACpC,SAAqB,EACrB,EAAE;IACF,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;IAChD,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,IAAI,4BAA4B,CAAC,gBAAgB,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;YAC5E,qBAAqB,CAAC,GAAG,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,qBAAqB,CAAC,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import assert from \"./assert\";\nimport { Community, CommunityIdentifier } from \"../types\";\nimport { areEquivalentCommunityAddresses } from \"./community-address\";\n\ntype LegacyCommunityRef = {\n address: string;\n name?: string;\n publicKey?: string;\n};\n\nexport type CommunityLookupRef = CommunityIdentifier | LegacyCommunityRef;\n\nconst getLegacyCommunityAddress = (communityRef: CommunityLookupRef) =>\n (communityRef as LegacyCommunityRef).address;\n\nexport const getCommunityRefKey = (communityRef: CommunityLookupRef): string => {\n const communityKey =\n communityRef.publicKey || getLegacyCommunityAddress(communityRef) || communityRef.name;\n assert(typeof communityKey === \"string\" && communityKey.length > 0, \"community ref missing key\");\n return communityKey;\n};\n\nexport const getCommunityRefKeys = (communityRefs: CommunityLookupRef[]) =>\n communityRefs.map(getCommunityRefKey);\n\nexport const getCommunityLookupOptions = (communityRefOrAddress: CommunityLookupRef | string) => {\n if (typeof communityRefOrAddress === \"string\") {\n return { address: communityRefOrAddress };\n }\n\n const legacyCommunityAddress = getLegacyCommunityAddress(communityRefOrAddress);\n if (legacyCommunityAddress) {\n return { address: legacyCommunityAddress };\n }\n\n const options: { name?: string; publicKey?: string } = {};\n if (communityRefOrAddress.name) {\n options.name = communityRefOrAddress.name;\n }\n if (communityRefOrAddress.publicKey) {\n options.publicKey = communityRefOrAddress.publicKey;\n }\n return options;\n};\n\nexport const mergeCommunityRefs = (\n base: CommunityLookupRef,\n extra: CommunityLookupRef,\n): CommunityLookupRef => {\n const mergedAddress = getLegacyCommunityAddress(base) || getLegacyCommunityAddress(extra);\n const mergedName = base.name || extra.name;\n const mergedPublicKey = base.publicKey || extra.publicKey;\n if (mergedPublicKey) {\n return {\n publicKey: mergedPublicKey,\n ...(mergedAddress ? { address: mergedAddress } : undefined),\n ...(mergedName ? { name: mergedName } : undefined),\n };\n }\n if (mergedAddress) {\n return {\n address: mergedAddress,\n ...(mergedName ? { name: mergedName } : undefined),\n };\n }\n assert(typeof mergedName === \"string\" && mergedName.length > 0, \"community ref missing name\");\n return { name: mergedName };\n};\n\nexport const getUniqueSortedCommunityRefs = (communityRefs?: CommunityLookupRef[]) => {\n const refsByKey = new Map<string, CommunityLookupRef>();\n for (const communityRef of communityRefs || []) {\n const communityKey = getCommunityRefKey(communityRef);\n const existingCommunityRef = refsByKey.get(communityKey);\n refsByKey.set(\n communityKey,\n existingCommunityRef ? mergeCommunityRefs(existingCommunityRef, communityRef) : communityRef,\n );\n }\n return [...refsByKey.entries()]\n .sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey))\n .map(([, communityRef]) => communityRef);\n};\n\nexport const isCommunityRef = (value: unknown): value is CommunityLookupRef => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return false;\n }\n\n const communityRef = value as { address?: unknown; name?: unknown; publicKey?: unknown };\n const hasAddress = typeof communityRef.address === \"string\" && communityRef.address.length > 0;\n const hasName = typeof communityRef.name === \"string\" && communityRef.name.length > 0;\n const hasPublicKey =\n typeof communityRef.publicKey === \"string\" && communityRef.publicKey.length > 0;\n\n return hasAddress || hasName || hasPublicKey;\n};\n\nexport function assertCommunityRef(\n value: unknown,\n label: string,\n): asserts value is CommunityLookupRef {\n assert(isCommunityRef(value), `${label} must be an object with address, name, or publicKey`);\n}\n\nexport const doesAddressMatchCommunityRef = (\n communityAddress: string | undefined,\n communityRef: CommunityLookupRef,\n community?: Community,\n) => {\n if (typeof communityAddress !== \"string\") {\n return false;\n }\n\n const legacyCommunityAddress = getLegacyCommunityAddress(communityRef);\n if (legacyCommunityAddress) {\n if (communityAddress === legacyCommunityAddress) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, legacyCommunityAddress)) {\n return true;\n }\n }\n if (communityRef.publicKey && communityAddress === communityRef.publicKey) {\n return true;\n }\n if (communityRef.name) {\n if (communityAddress === communityRef.name) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, communityRef.name)) {\n return true;\n }\n }\n\n const communityIdentifiers = [community?.address, community?.publicKey, community?.name];\n for (const identifier of communityIdentifiers) {\n if (typeof identifier !== \"string\") {\n continue;\n }\n if (communityAddress === identifier) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, identifier)) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getMatchingCommunityRefKeys = (\n communityRefs: CommunityLookupRef[],\n communityAddress: string | undefined,\n community?: Community,\n) => {\n const matchingCommunityKeys = new Set<string>();\n for (const communityRef of communityRefs) {\n if (doesAddressMatchCommunityRef(communityAddress, communityRef, community)) {\n matchingCommunityKeys.add(getCommunityRefKey(communityRef));\n }\n }\n return [...matchingCommunityKeys];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"community-ref.js","sourceRoot":"","sources":["../../src/lib/community-ref.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AAUtE,MAAM,yBAAyB,GAAG,CAAC,YAAgC,EAAE,EAAE,CACpE,YAAmC,CAAC,OAAO,CAAC;AAE/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAAgC,EAAU,EAAE;IAC7E,MAAM,YAAY,GAChB,YAAY,CAAC,SAAS,IAAI,yBAAyB,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC;IACzF,MAAM,CAAC,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,2BAA2B,CAAC,CAAC;IACjG,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,aAAmC,EAAE,EAAE,CACzE,aAAa,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,qBAAkD,EAAE,EAAE;IAC9F,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,sBAAsB,GAAG,yBAAyB,CAAC,qBAAqB,CAAC,CAAC;IAChF,IAAI,sBAAsB,EAAE,CAAC;QAC3B,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAC7C,CAAC;IAED,MAAM,OAAO,GAA0C,EAAE,CAAC;IAC1D,IAAI,qBAAqB,CAAC,IAAI,EAAE,CAAC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AAE,IAAI,CAAC,CAAC;IACzF,KAAK,MAAM,UAAU,IAAI,oBAAoB,EAAE,CAAC;QAC9C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,SAAS;QACX,CAAC;QACD,IAAI,gBAAgB,KAAK,UAAU,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,+BAA+B,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,CAAC;YAClE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,gBAA4D,EAC5D,YAA4C,EAC5C,SAAqB,EACrB,EAAE,CACF,MAAM,CAAC,IAAI,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,IAAI,CACtC,CAAC,cAAc,EAAE,EAAE,CACjB,YAAY,IAAI,4BAA4B,CAAC,cAAc,EAAE,YAAY,EAAE,SAAS,CAAC,CACxF,CAAC;AAEJ,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,aAAmC,EACnC,gBAAoC,EACpC,SAAqB,EACrB,EAAE;IACF,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;IAChD,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,IAAI,4BAA4B,CAAC,gBAAgB,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;YAC5E,qBAAqB,CAAC,GAAG,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,qBAAqB,CAAC,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import assert from \"./assert\";\nimport { Community, CommunityIdentifier } from \"../types\";\nimport { areEquivalentCommunityAddresses } from \"./community-address\";\n\ntype LegacyCommunityRef = {\n address: string;\n name?: string;\n publicKey?: string;\n};\n\nexport type CommunityLookupRef = CommunityIdentifier | LegacyCommunityRef;\n\nconst getLegacyCommunityAddress = (communityRef: CommunityLookupRef) =>\n (communityRef as LegacyCommunityRef).address;\n\nexport const getCommunityRefKey = (communityRef: CommunityLookupRef): string => {\n const communityKey =\n communityRef.publicKey || getLegacyCommunityAddress(communityRef) || communityRef.name;\n assert(typeof communityKey === \"string\" && communityKey.length > 0, \"community ref missing key\");\n return communityKey;\n};\n\nexport const getCommunityRefKeys = (communityRefs: CommunityLookupRef[]) =>\n communityRefs.map(getCommunityRefKey);\n\nexport const getCommunityLookupOptions = (communityRefOrAddress: CommunityLookupRef | string) => {\n if (typeof communityRefOrAddress === \"string\") {\n return { address: communityRefOrAddress };\n }\n\n const legacyCommunityAddress = getLegacyCommunityAddress(communityRefOrAddress);\n if (legacyCommunityAddress) {\n return { address: legacyCommunityAddress };\n }\n\n const options: { name?: string; publicKey?: string } = {};\n if (communityRefOrAddress.name) {\n options.name = communityRefOrAddress.name;\n }\n if (communityRefOrAddress.publicKey) {\n options.publicKey = communityRefOrAddress.publicKey;\n }\n return options;\n};\n\nexport const mergeCommunityRefs = (\n base: CommunityLookupRef,\n extra: CommunityLookupRef,\n): CommunityLookupRef => {\n const mergedAddress = getLegacyCommunityAddress(base) || getLegacyCommunityAddress(extra);\n const mergedName = base.name || extra.name;\n const mergedPublicKey = base.publicKey || extra.publicKey;\n if (mergedPublicKey) {\n return {\n publicKey: mergedPublicKey,\n ...(mergedAddress ? { address: mergedAddress } : undefined),\n ...(mergedName ? { name: mergedName } : undefined),\n };\n }\n if (mergedAddress) {\n return {\n address: mergedAddress,\n ...(mergedName ? { name: mergedName } : undefined),\n };\n }\n assert(typeof mergedName === \"string\" && mergedName.length > 0, \"community ref missing name\");\n return { name: mergedName };\n};\n\nexport const getUniqueSortedCommunityRefs = (communityRefs?: CommunityLookupRef[]) => {\n const refsByKey = new Map<string, CommunityLookupRef>();\n for (const communityRef of communityRefs || []) {\n const communityKey = getCommunityRefKey(communityRef);\n const existingCommunityRef = refsByKey.get(communityKey);\n refsByKey.set(\n communityKey,\n existingCommunityRef ? mergeCommunityRefs(existingCommunityRef, communityRef) : communityRef,\n );\n }\n return [...refsByKey.entries()]\n .sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey))\n .map(([, communityRef]) => communityRef);\n};\n\nexport const isCommunityRef = (value: unknown): value is CommunityLookupRef => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return false;\n }\n\n const communityRef = value as { address?: unknown; name?: unknown; publicKey?: unknown };\n const hasAddress = typeof communityRef.address === \"string\" && communityRef.address.length > 0;\n const hasName = typeof communityRef.name === \"string\" && communityRef.name.length > 0;\n const hasPublicKey =\n typeof communityRef.publicKey === \"string\" && communityRef.publicKey.length > 0;\n\n return hasAddress || hasName || hasPublicKey;\n};\n\nexport function assertCommunityRef(\n value: unknown,\n label: string,\n): asserts value is CommunityLookupRef {\n assert(isCommunityRef(value), `${label} must be an object with address, name, or publicKey`);\n}\n\nexport const doesAddressMatchCommunityRef = (\n communityAddress: string | undefined,\n communityRef: CommunityLookupRef,\n community?: Community,\n) => {\n if (typeof communityAddress !== \"string\") {\n return false;\n }\n\n const legacyCommunityAddress = getLegacyCommunityAddress(communityRef);\n if (legacyCommunityAddress) {\n if (communityAddress === legacyCommunityAddress) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, legacyCommunityAddress)) {\n return true;\n }\n }\n if (communityRef.publicKey && communityAddress === communityRef.publicKey) {\n return true;\n }\n if (communityRef.name) {\n if (communityAddress === communityRef.name) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, communityRef.name)) {\n return true;\n }\n }\n\n const communityIdentifiers = [community?.address, community?.publicKey, community?.name];\n for (const identifier of communityIdentifiers) {\n if (typeof identifier !== \"string\") {\n continue;\n }\n if (communityAddress === identifier) {\n return true;\n }\n if (areEquivalentCommunityAddresses(communityAddress, identifier)) {\n return true;\n }\n }\n\n return false;\n};\n\n// whether an account's blocked addresses block a community, as feeds leave it out\nexport const isCommunityRefBlocked = (\n blockedAddresses: { [address: string]: unknown } | undefined,\n communityRef: CommunityLookupRef | undefined,\n community?: Community,\n) =>\n Object.keys(blockedAddresses || {}).some(\n (blockedAddress) =>\n communityRef && doesAddressMatchCommunityRef(blockedAddress, communityRef, community),\n );\n\nexport const getMatchingCommunityRefKeys = (\n communityRefs: CommunityLookupRef[],\n communityAddress: string | undefined,\n community?: Community,\n) => {\n const matchingCommunityKeys = new Set<string>();\n for (const communityRef of communityRefs) {\n if (doesAddressMatchCommunityRef(communityAddress, communityRef, community)) {\n matchingCommunityKeys.add(getCommunityRefKey(communityRef));\n }\n }\n return [...matchingCommunityKeys];\n};\n"]}
|
package/dist/lib/pkc-compat.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Challenge, ChallengeAnswersByIndex, PublishChallengeAnswersInput } from "../types.js";
|
|
1
2
|
import type { PkcResolveAuthorName, PkcResolveAuthorNameOptions } from "./pkc-types.js";
|
|
2
3
|
export declare const getProtocolClient: (account: any) => any;
|
|
3
4
|
export declare const getProtocolOptions: (account: any) => any;
|
|
@@ -27,12 +28,25 @@ export declare const normalizeOptionsForPkcClient: <T extends Record<string, any
|
|
|
27
28
|
export declare const getPkcClientOptions: <T extends Record<string, any> | undefined>(account: any, options: T) => Promise<T>;
|
|
28
29
|
export declare const normalizeAccountProtocolConfig: <T extends Record<string, any> | undefined>(account: T, defaultChainProviders?: Record<string, any>) => T;
|
|
29
30
|
export declare const withProtocolAliases: <T extends Record<string, any>>(account: T, protocolClient?: any, protocolOptions?: any) => T;
|
|
30
|
-
type ChallengeAnswersInput = string[] | {
|
|
31
|
-
challengeAnswers?: string[];
|
|
32
|
-
} | undefined;
|
|
33
|
-
export declare const normalizeChallengeAnswersForPkc: (challengeAnswers: ChallengeAnswersInput) => {
|
|
31
|
+
type ChallengeAnswersInput = PublishChallengeAnswersInput | string[] | {
|
|
34
32
|
challengeAnswers: string[];
|
|
33
|
+
} | undefined;
|
|
34
|
+
/** The challenge indexes a CHALLENGE message asks to answer, in ascending order. */
|
|
35
|
+
export declare const getChallengeIndexes: (challenge: Challenge | undefined) => string[];
|
|
36
|
+
/**
|
|
37
|
+
* Converts publishChallengeAnswers() input to pkc-js's { challengeAnswers: { [challengeIndex]: answer } }.
|
|
38
|
+
* A deprecated positional array is mapped onto `challengeIndexes`, the ascending keys of the latest
|
|
39
|
+
* CHALLENGE, so a caller that still passes an array keeps working. Missing or empty answers throw
|
|
40
|
+
* instead of becoming an empty record that pkc-js would reject with a schema error.
|
|
41
|
+
*/
|
|
42
|
+
export declare const normalizeChallengeAnswersForPkc: (challengeAnswers: ChallengeAnswersInput, challengeIndexes?: string[]) => {
|
|
43
|
+
challengeAnswers: ChallengeAnswersByIndex;
|
|
35
44
|
};
|
|
36
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Lets publication.publishChallengeAnswers() take the hooks' input forms. Call it with every
|
|
47
|
+
* CHALLENGE the publication receives: the publication is wrapped once, and the challenge indexes
|
|
48
|
+
* used to map a deprecated array are those of the latest CHALLENGE.
|
|
49
|
+
*/
|
|
50
|
+
export declare const withPublishChallengeAnswersCompat: <T>(publication: T, challenge: Challenge) => T;
|
|
37
51
|
export * from "./protocol-compat.js";
|
|
38
52
|
//# sourceMappingURL=pkc-compat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkc-compat.d.ts","sourceRoot":"","sources":["../../src/lib/pkc-compat.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,2BAA2B,EAE5B,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,QAAiB,CAAC;AAEhE,eAAO,MAAM,kBAAkB,GAAI,SAAS,GAAG,QAAwB,CAAC;AAExE,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,QAC0B,CAAC;AAEzE,eAAO,MAAM,8BAA8B,GAAI,SAAS,GAAG,QACuC,CA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AE,gBAAgB,EAAE,MAAM,EAAE,CAAA;CAAE,GAC9B,SAAS,CAAC;AAUd,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,GAAI,WAAW,SAAS,GAAG,SAAS,KAAG,MAAM,EAM5E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,GAC1C,kBAAkB,qBAAqB,EACvC,mBAAkB,MAAM,EAAO,KAC9B;IAAE,gBAAgB,EAAE,uBAAuB,CAAA;CA2B7C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAI,CAAC,EAAE,aAAa,CAAC,EAAE,WAAW,SAAS,KAAG,CAmB3F,CAAC;AAEF,cAAc,mBAAmB,CAAC"}
|
package/dist/lib/pkc-compat.js
CHANGED
|
@@ -156,20 +156,59 @@ export const withProtocolAliases = (account, protocolClient, protocolOptions) =>
|
|
|
156
156
|
return nextAccount;
|
|
157
157
|
};
|
|
158
158
|
const publishChallengeAnswersCompatMarker = Symbol.for("bitsocial-react-hooks.publishChallengeAnswersCompat");
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
const challengeIndexesKey = Symbol.for("bitsocial-react-hooks.challengeIndexes");
|
|
160
|
+
const emptyChallengeAnswersMessage = 'publishChallengeAnswers() needs a non-empty record of answers keyed by challenge index, for example { "0": "answer" }';
|
|
161
|
+
/** The challenge indexes a CHALLENGE message asks to answer, in ascending order. */
|
|
162
|
+
export const getChallengeIndexes = (challenge) => {
|
|
163
|
+
const challenges = challenge === null || challenge === void 0 ? void 0 : challenge.challenges;
|
|
164
|
+
if (!challenges || typeof challenges !== "object") {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
return Object.keys(challenges).sort((a, b) => Number(a) - Number(b));
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Converts publishChallengeAnswers() input to pkc-js's { challengeAnswers: { [challengeIndex]: answer } }.
|
|
171
|
+
* A deprecated positional array is mapped onto `challengeIndexes`, the ascending keys of the latest
|
|
172
|
+
* CHALLENGE, so a caller that still passes an array keeps working. Missing or empty answers throw
|
|
173
|
+
* instead of becoming an empty record that pkc-js would reject with a schema error.
|
|
174
|
+
*/
|
|
175
|
+
export const normalizeChallengeAnswersForPkc = (challengeAnswers, challengeIndexes = []) => {
|
|
176
|
+
const answers = challengeAnswers &&
|
|
177
|
+
typeof challengeAnswers === "object" &&
|
|
178
|
+
!Array.isArray(challengeAnswers) &&
|
|
179
|
+
Object.prototype.hasOwnProperty.call(challengeAnswers, "challengeAnswers")
|
|
180
|
+
? challengeAnswers.challengeAnswers
|
|
181
|
+
: challengeAnswers;
|
|
182
|
+
if (Array.isArray(answers)) {
|
|
183
|
+
assert(answers.length > 0, emptyChallengeAnswersMessage);
|
|
184
|
+
assert(challengeIndexes.length > 0, "publishChallengeAnswers() can't map an array of answers before a challenge message is received, pass a record keyed by challenge index");
|
|
185
|
+
const answersByIndex = {};
|
|
186
|
+
challengeIndexes.slice(0, answers.length).forEach((challengeIndex, position) => {
|
|
187
|
+
answersByIndex[challengeIndex] = answers[position];
|
|
188
|
+
});
|
|
189
|
+
return { challengeAnswers: answersByIndex };
|
|
190
|
+
}
|
|
191
|
+
assert(answers && typeof answers === "object" && Object.keys(answers).length > 0, emptyChallengeAnswersMessage);
|
|
192
|
+
return { challengeAnswers: answers };
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Lets publication.publishChallengeAnswers() take the hooks' input forms. Call it with every
|
|
196
|
+
* CHALLENGE the publication receives: the publication is wrapped once, and the challenge indexes
|
|
197
|
+
* used to map a deprecated array are those of the latest CHALLENGE.
|
|
198
|
+
*/
|
|
199
|
+
export const withPublishChallengeAnswersCompat = (publication, challenge) => {
|
|
165
200
|
const target = publication;
|
|
166
|
-
if (!target ||
|
|
167
|
-
|
|
168
|
-
|
|
201
|
+
if (!target || typeof target.publishChallengeAnswers !== "function") {
|
|
202
|
+
return publication;
|
|
203
|
+
}
|
|
204
|
+
target[challengeIndexesKey] = getChallengeIndexes(challenge);
|
|
205
|
+
if (target[publishChallengeAnswersCompatMarker]) {
|
|
169
206
|
return publication;
|
|
170
207
|
}
|
|
171
208
|
const publishChallengeAnswers = target.publishChallengeAnswers.bind(publication);
|
|
172
|
-
target.publishChallengeAnswers = (challengeAnswers) =>
|
|
209
|
+
target.publishChallengeAnswers = (challengeAnswers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
|
+
return publishChallengeAnswers(normalizeChallengeAnswersForPkc(challengeAnswers, target[challengeIndexesKey]));
|
|
211
|
+
});
|
|
173
212
|
target[publishChallengeAnswersCompatMarker] = true;
|
|
174
213
|
return publication;
|
|
175
214
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkc-compat.js","sourceRoot":"","sources":["../../src/lib/pkc-compat.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAO9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC;AAEhE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC;AAExE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAY,EAAE,EAAE,WAChD,OAAA,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,MAAI,MAAA,kBAAkB,CAAC,OAAO,CAAC,0CAAE,cAAc,CAAA,CAAA,EAAA,CAAC;AAEzE,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,OAAY,EAAE,EAAE,WAC7D,OAAA,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,2BAA2B,MAAI,MAAA,kBAAkB,CAAC,OAAO,CAAC,0CAAE,2BAA2B,CAAA,CAA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B,CAAC","sourcesContent":["import assert from \"./assert\";\nimport type {\n PkcResolveAuthorName,\n PkcResolveAuthorNameOptions,\n PkcResolveAuthorNameResult,\n} from \"./pkc-types\";\n\nexport const getProtocolClient = (account: any) => account?.pkc;\n\nexport const getProtocolOptions = (account: any) => account?.pkcOptions;\n\nexport const getChainProviders = (account: any) =>\n account?.chainProviders || getProtocolOptions(account)?.chainProviders;\n\nexport const getNameResolversChainProviders = (account: any) =>\n account?.nameResolversChainProviders || getProtocolOptions(account)?.nameResolversChainProviders;\n\nexport const getRpcClients = (protocolClient: any) => protocolClient?.clients?.pkcRpcClients || {};\n\nexport const getPageRpcClients = (clients: any) => clients?.pkcRpcClients || {};\n\nexport const getProtocolNameResolverClients = (protocolClient: any) =>\n protocolClient?.clients?.nameResolvers ||\n protocolClient?._clientsManager?.clients?.nameResolvers ||\n {};\n\nexport type NameResolverInfo = {\n key: string;\n nameSystem: string;\n chainTicker: string;\n provider: string;\n providerLabel: string;\n};\n\nconst isEthAliasDomain = (address?: string) =>\n typeof address === \"string\" &&\n (address.toLowerCase().endsWith(\".eth\") || address.toLowerCase().endsWith(\".bso\"));\n\nconst isSupportedBsoResolverProvider = (provider: string) =>\n provider === \"viem\" || /^(https?:\\/\\/|wss?:\\/\\/)/i.test(provider);\n\nconst getNameResolverProviderLabel = (provider: string) => {\n try {\n return new URL(provider).hostname;\n } catch (error) {\n return provider;\n }\n};\n\nconst getConfiguredEthNameResolverProviders = (account: any): string[] => {\n const nameResolverUrls = getNameResolversChainProviders(account)?.eth?.urls;\n const chainProviderUrls = getChainProviders(account)?.eth?.urls;\n const urls =\n Array.isArray(nameResolverUrls) && nameResolverUrls.length\n ? nameResolverUrls\n : chainProviderUrls;\n\n if (!Array.isArray(urls)) {\n return [];\n }\n\n return urls.filter(\n (provider): provider is string => typeof provider === \"string\" && provider.length > 0,\n );\n};\n\nexport const getConfiguredNameResolverInfoByKey = (\n account: any,\n): Record<string, NameResolverInfo> => {\n const infoByKey: Record<string, NameResolverInfo> = {};\n\n for (const provider of getConfiguredEthNameResolverProviders(account)) {\n if (!isSupportedBsoResolverProvider(provider)) {\n continue;\n }\n\n const providerLabel = getNameResolverProviderLabel(provider);\n const key = `eth-${providerLabel}`;\n\n if (!infoByKey[key]) {\n infoByKey[key] = {\n key,\n nameSystem: \"eth\",\n chainTicker: \"eth\",\n provider,\n providerLabel,\n };\n }\n }\n\n return infoByKey;\n};\n\nexport const getMatchingNameResolvers = (account: any, address?: string): NameResolverInfo[] => {\n if (!isEthAliasDomain(address)) {\n return [];\n }\n\n return Object.values(getConfiguredNameResolverInfoByKey(account));\n};\n\nconst buildConfiguredNameResolvers = async (account: any, dataPath?: string) => {\n const resolverInfos = Object.values(getConfiguredNameResolverInfoByKey(account));\n if (!resolverInfos.length) {\n return [];\n }\n // bso-resolver bundles viem; load it when a PKC client is created rather than with the hooks\n // that apps import at startup.\n const { BsoResolver } = await import(\"@bitsocial/bso-resolver\");\n return resolverInfos.map(\n (resolverInfo) =>\n new BsoResolver({\n key: resolverInfo.key,\n provider: resolverInfo.provider,\n dataPath,\n }),\n );\n};\n\ntype LegacyResolveAuthorAddress = (options: { address: string }) => Promise<string> | string;\n\ntype AuthorNameProtocolClient = {\n resolveAuthorName?: PkcResolveAuthorName;\n resolveAuthorAddress?: LegacyResolveAuthorAddress;\n};\n\nconst normalizeResolvedAuthorName = (result: PkcResolveAuthorNameResult | string): string => {\n if (typeof result === \"string\") {\n return result;\n }\n\n assert(\n typeof result?.resolvedAuthorName === \"string\",\n \"protocol client resolveAuthorName returned invalid resolvedAuthorName\",\n );\n return result.resolvedAuthorName;\n};\n\nexport const resolveAuthorNameWithProtocol = async (\n protocolClient: AuthorNameProtocolClient | undefined,\n options: PkcResolveAuthorNameOptions,\n): Promise<string> => {\n const resolveAuthorName = protocolClient?.resolveAuthorName;\n if (typeof resolveAuthorName === \"function\") {\n return normalizeResolvedAuthorName(await resolveAuthorName.call(protocolClient, options));\n }\n\n const resolveAuthorAddress = protocolClient?.resolveAuthorAddress;\n assert(\n typeof resolveAuthorAddress === \"function\",\n \"protocol client resolveAuthorName/resolveAuthorAddress missing\",\n );\n return resolveAuthorAddress.call(protocolClient, { address: options.name });\n};\n\nexport const normalizeOptionsForPkcClient = <T extends Record<string, any> | undefined>(\n options: T,\n): T => {\n if (!options) {\n return options;\n }\n\n const normalized: Record<string, any> = { ...options };\n\n if (normalized.resolveAuthorNames == null && normalized.resolveAuthorAddresses != null) {\n normalized.resolveAuthorNames = normalized.resolveAuthorAddresses;\n }\n\n delete normalized.resolveAuthorAddresses;\n delete normalized.chainProviders;\n delete normalized.nameResolversChainProviders;\n\n return normalized as T;\n};\n\nexport const getPkcClientOptions = async <T extends Record<string, any> | undefined>(\n account: any,\n options: T,\n): Promise<T> => {\n const normalized = normalizeOptionsForPkcClient(options);\n\n if (!normalized) {\n return normalized;\n }\n\n const nameResolvers = await buildConfiguredNameResolvers(account, normalized.dataPath);\n if (nameResolvers.length) {\n normalized.nameResolvers = nameResolvers;\n }\n\n return normalized as T;\n};\n\nexport const normalizeAccountProtocolConfig = <T extends Record<string, any> | undefined>(\n account: T,\n defaultChainProviders?: Record<string, any>,\n): T => {\n if (!account) {\n return account;\n }\n\n const nextAccount: Record<string, any> = { ...account };\n const protocolOptions =\n nextAccount.pkcOptions && typeof nextAccount.pkcOptions === \"object\"\n ? { ...nextAccount.pkcOptions }\n : nextAccount.pkcOptions;\n\n const chainProviders =\n nextAccount.chainProviders || protocolOptions?.chainProviders || defaultChainProviders;\n if (chainProviders !== undefined) {\n nextAccount.chainProviders = chainProviders;\n }\n\n if (\n nextAccount.nameResolversChainProviders === undefined &&\n protocolOptions?.nameResolversChainProviders !== undefined\n ) {\n nextAccount.nameResolversChainProviders = protocolOptions.nameResolversChainProviders;\n }\n\n if (protocolOptions && typeof protocolOptions === \"object\") {\n delete protocolOptions.chainProviders;\n delete protocolOptions.nameResolversChainProviders;\n nextAccount.pkcOptions = protocolOptions;\n }\n\n return nextAccount as T;\n};\n\nexport const withProtocolAliases = <T extends Record<string, any>>(\n account: T,\n protocolClient?: any,\n protocolOptions?: any,\n): T => {\n const nextAccount: Record<string, any> = { ...account };\n\n if (protocolClient !== undefined) {\n nextAccount.pkc = protocolClient;\n }\n if (protocolOptions !== undefined) {\n nextAccount.pkcOptions = protocolOptions;\n }\n\n return nextAccount as T;\n};\n\ntype ChallengeAnswersInput = string[] | { challengeAnswers?: string[] } | undefined;\n\nconst publishChallengeAnswersCompatMarker = Symbol.for(\n \"bitsocial-react-hooks.publishChallengeAnswersCompat\",\n);\n\nexport const normalizeChallengeAnswersForPkc = (challengeAnswers: ChallengeAnswersInput) => ({\n challengeAnswers: Array.isArray(challengeAnswers)\n ? challengeAnswers\n : challengeAnswers?.challengeAnswers || [],\n});\n\nexport const withPublishChallengeAnswersCompat = <T>(publication: T): T => {\n const target = publication as Record<string | symbol, any> | undefined;\n if (\n !target ||\n typeof target.publishChallengeAnswers !== \"function\" ||\n target[publishChallengeAnswersCompatMarker]\n ) {\n return publication;\n }\n\n const publishChallengeAnswers = target.publishChallengeAnswers.bind(publication);\n target.publishChallengeAnswers = (challengeAnswers?: ChallengeAnswersInput) =>\n publishChallengeAnswers(normalizeChallengeAnswersForPkc(challengeAnswers));\n target[publishChallengeAnswersCompatMarker] = true;\n\n return publication;\n};\n\nexport * from \"./protocol-compat\";\n"]}
|
|
1
|
+
{"version":3,"file":"pkc-compat.js","sourceRoot":"","sources":["../../src/lib/pkc-compat.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAQ9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC;AAEhE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC;AAExE,MAAM,CAAC,MAAM,i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AM,CAAC,MAAM,iCAAiC,GAAG,CAAI,WAAc,EAAE,SAAoB,EAAK,EAAE;IAC9F,MAAM,MAAM,GAAG,WAAuD,CAAC;IACvE,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,uBAAuB,KAAK,UAAU,EAAE,CAAC;QACpE,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC7D,IAAI,MAAM,CAAC,mCAAmC,CAAC,EAAE,CAAC;QAChD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,uBAAuB,GAAG,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjF,MAAM,CAAC,uBAAuB,GAAG,CAAO,gBAAuC,EAAE,EAAE;QACjF,OAAA,uBAAuB,CACrB,+BAA+B,CAAC,gBAAgB,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAC/E,CAAA;MAAA,CAAC;IACJ,MAAM,CAAC,mCAAmC,CAAC,GAAG,IAAI,CAAC;IAEnD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF,cAAc,mBAAmB,CAAC","sourcesContent":["import assert from \"./assert\";\nimport type { Challenge, ChallengeAnswersByIndex, PublishChallengeAnswersInput } from \"../types\";\nimport type {\n PkcResolveAuthorName,\n PkcResolveAuthorNameOptions,\n PkcResolveAuthorNameResult,\n} from \"./pkc-types\";\n\nexport const getProtocolClient = (account: any) => account?.pkc;\n\nexport const getProtocolOptions = (account: any) => account?.pkcOptions;\n\nexport const getChainProviders = (account: any) =>\n account?.chainProviders || getProtocolOptions(account)?.chainProviders;\n\nexport const getNameResolversChainProviders = (account: any) =>\n account?.nameResolversChainProviders || getProtocolOptions(account)?.nameResolversChainProviders;\n\nexport const getRpcClients = (protocolClient: any) => protocolClient?.clients?.pkcRpcClients || {};\n\nexport const getPageRpcClients = (clients: any) => clients?.pkcRpcClients || {};\n\nexport const getProtocolNameResolverClients = (protocolClient: any) =>\n protocolClient?.clients?.nameResolvers ||\n protocolClient?._clientsManager?.clients?.nameResolvers ||\n {};\n\nexport type NameResolverInfo = {\n key: string;\n nameSystem: string;\n chainTicker: string;\n provider: string;\n providerLabel: string;\n};\n\nconst isEthAliasDomain = (address?: string) =>\n typeof address === \"string\" &&\n (address.toLowerCase().endsWith(\".eth\") || address.toLowerCase().endsWith(\".bso\"));\n\nconst isSupportedBsoResolverProvider = (provider: string) =>\n provider === \"viem\" || /^(https?:\\/\\/|wss?:\\/\\/)/i.test(provider);\n\nconst getNameResolverProviderLabel = (provider: string) => {\n try {\n return new URL(provider).hostname;\n } catch (error) {\n return provider;\n }\n};\n\nconst getConfiguredEthNameResolverProviders = (account: any): string[] => {\n const nameResolverUrls = getNameResolversChainProviders(account)?.eth?.urls;\n const chainProviderUrls = getChainProviders(account)?.eth?.urls;\n const urls =\n Array.isArray(nameResolverUrls) && nameResolverUrls.length\n ? nameResolverUrls\n : chainProviderUrls;\n\n if (!Array.isArray(urls)) {\n return [];\n }\n\n return urls.filter(\n (provider): provider is string => typeof provider === \"string\" && provider.length > 0,\n );\n};\n\nexport const getConfiguredNameResolverInfoByKey = (\n account: any,\n): Record<string, NameResolverInfo> => {\n const infoByKey: Record<string, NameResolverInfo> = {};\n\n for (const provider of getConfiguredEthNameResolverProviders(account)) {\n if (!isSupportedBsoResolverProvider(provider)) {\n continue;\n }\n\n const providerLabel = getNameResolverProviderLabel(provider);\n const key = `eth-${providerLabel}`;\n\n if (!infoByKey[key]) {\n infoByKey[key] = {\n key,\n nameSystem: \"eth\",\n chainTicker: \"eth\",\n provider,\n providerLabel,\n };\n }\n }\n\n return infoByKey;\n};\n\nexport const getMatchingNameResolvers = (account: any, address?: string): NameResolverInfo[] => {\n if (!isEthAliasDomain(address)) {\n return [];\n }\n\n return Object.values(getConfiguredNameResolverInfoByKey(account));\n};\n\nconst buildConfiguredNameResolvers = async (account: any, dataPath?: string) => {\n const resolverInfos = Object.values(getConfiguredNameResolverInfoByKey(account));\n if (!resolverInfos.length) {\n return [];\n }\n // bso-resolver bundles viem; load it when a PKC client is created rather than with the hooks\n // that apps import at startup.\n const { BsoResolver } = await import(\"@bitsocial/bso-resolver\");\n return resolverInfos.map(\n (resolverInfo) =>\n new BsoResolver({\n key: resolverInfo.key,\n provider: resolverInfo.provider,\n dataPath,\n }),\n );\n};\n\ntype LegacyResolveAuthorAddress = (options: { address: string }) => Promise<string> | string;\n\ntype AuthorNameProtocolClient = {\n resolveAuthorName?: PkcResolveAuthorName;\n resolveAuthorAddress?: LegacyResolveAuthorAddress;\n};\n\nconst normalizeResolvedAuthorName = (result: PkcResolveAuthorNameResult | string): string => {\n if (typeof result === \"string\") {\n return result;\n }\n\n assert(\n typeof result?.resolvedAuthorName === \"string\",\n \"protocol client resolveAuthorName returned invalid resolvedAuthorName\",\n );\n return result.resolvedAuthorName;\n};\n\nexport const resolveAuthorNameWithProtocol = async (\n protocolClient: AuthorNameProtocolClient | undefined,\n options: PkcResolveAuthorNameOptions,\n): Promise<string> => {\n const resolveAuthorName = protocolClient?.resolveAuthorName;\n if (typeof resolveAuthorName === \"function\") {\n return normalizeResolvedAuthorName(await resolveAuthorName.call(protocolClient, options));\n }\n\n const resolveAuthorAddress = protocolClient?.resolveAuthorAddress;\n assert(\n typeof resolveAuthorAddress === \"function\",\n \"protocol client resolveAuthorName/resolveAuthorAddress missing\",\n );\n return resolveAuthorAddress.call(protocolClient, { address: options.name });\n};\n\nexport const normalizeOptionsForPkcClient = <T extends Record<string, any> | undefined>(\n options: T,\n): T => {\n if (!options) {\n return options;\n }\n\n const normalized: Record<string, any> = { ...options };\n\n if (normalized.resolveAuthorNames == null && normalized.resolveAuthorAddresses != null) {\n normalized.resolveAuthorNames = normalized.resolveAuthorAddresses;\n }\n\n delete normalized.resolveAuthorAddresses;\n delete normalized.chainProviders;\n delete normalized.nameResolversChainProviders;\n\n return normalized as T;\n};\n\nexport const getPkcClientOptions = async <T extends Record<string, any> | undefined>(\n account: any,\n options: T,\n): Promise<T> => {\n const normalized = normalizeOptionsForPkcClient(options);\n\n if (!normalized) {\n return normalized;\n }\n\n const nameResolvers = await buildConfiguredNameResolvers(account, normalized.dataPath);\n if (nameResolvers.length) {\n normalized.nameResolvers = nameResolvers;\n }\n\n return normalized as T;\n};\n\nexport const normalizeAccountProtocolConfig = <T extends Record<string, any> | undefined>(\n account: T,\n defaultChainProviders?: Record<string, any>,\n): T => {\n if (!account) {\n return account;\n }\n\n const nextAccount: Record<string, any> = { ...account };\n const protocolOptions =\n nextAccount.pkcOptions && typeof nextAccount.pkcOptions === \"object\"\n ? { ...nextAccount.pkcOptions }\n : nextAccount.pkcOptions;\n\n const chainProviders =\n nextAccount.chainProviders || protocolOptions?.chainProviders || defaultChainProviders;\n if (chainProviders !== undefined) {\n nextAccount.chainProviders = chainProviders;\n }\n\n if (\n nextAccount.nameResolversChainProviders === undefined &&\n protocolOptions?.nameResolversChainProviders !== undefined\n ) {\n nextAccount.nameResolversChainProviders = protocolOptions.nameResolversChainProviders;\n }\n\n if (protocolOptions && typeof protocolOptions === \"object\") {\n delete protocolOptions.chainProviders;\n delete protocolOptions.nameResolversChainProviders;\n nextAccount.pkcOptions = protocolOptions;\n }\n\n return nextAccount as T;\n};\n\nexport const withProtocolAliases = <T extends Record<string, any>>(\n account: T,\n protocolClient?: any,\n protocolOptions?: any,\n): T => {\n const nextAccount: Record<string, any> = { ...account };\n\n if (protocolClient !== undefined) {\n nextAccount.pkc = protocolClient;\n }\n if (protocolOptions !== undefined) {\n nextAccount.pkcOptions = protocolOptions;\n }\n\n return nextAccount as T;\n};\n\ntype ChallengeAnswersInput =\n | PublishChallengeAnswersInput\n | string[]\n | { challengeAnswers: string[] }\n | undefined;\n\nconst publishChallengeAnswersCompatMarker = Symbol.for(\n \"bitsocial-react-hooks.publishChallengeAnswersCompat\",\n);\nconst challengeIndexesKey = Symbol.for(\"bitsocial-react-hooks.challengeIndexes\");\n\nconst emptyChallengeAnswersMessage =\n 'publishChallengeAnswers() needs a non-empty record of answers keyed by challenge index, for example { \"0\": \"answer\" }';\n\n/** The challenge indexes a CHALLENGE message asks to answer, in ascending order. */\nexport const getChallengeIndexes = (challenge: Challenge | undefined): string[] => {\n const challenges = challenge?.challenges;\n if (!challenges || typeof challenges !== \"object\") {\n return [];\n }\n return Object.keys(challenges).sort((a, b) => Number(a) - Number(b));\n};\n\n/**\n * Converts publishChallengeAnswers() input to pkc-js's { challengeAnswers: { [challengeIndex]: answer } }.\n * A deprecated positional array is mapped onto `challengeIndexes`, the ascending keys of the latest\n * CHALLENGE, so a caller that still passes an array keeps working. Missing or empty answers throw\n * instead of becoming an empty record that pkc-js would reject with a schema error.\n */\nexport const normalizeChallengeAnswersForPkc = (\n challengeAnswers: ChallengeAnswersInput,\n challengeIndexes: string[] = [],\n): { challengeAnswers: ChallengeAnswersByIndex } => {\n const answers =\n challengeAnswers &&\n typeof challengeAnswers === \"object\" &&\n !Array.isArray(challengeAnswers) &&\n Object.prototype.hasOwnProperty.call(challengeAnswers, \"challengeAnswers\")\n ? (challengeAnswers as { challengeAnswers: unknown }).challengeAnswers\n : challengeAnswers;\n\n if (Array.isArray(answers)) {\n assert(answers.length > 0, emptyChallengeAnswersMessage);\n assert(\n challengeIndexes.length > 0,\n \"publishChallengeAnswers() can't map an array of answers before a challenge message is received, pass a record keyed by challenge index\",\n );\n const answersByIndex: ChallengeAnswersByIndex = {};\n challengeIndexes.slice(0, answers.length).forEach((challengeIndex, position) => {\n answersByIndex[challengeIndex] = answers[position];\n });\n return { challengeAnswers: answersByIndex };\n }\n\n assert(\n answers && typeof answers === \"object\" && Object.keys(answers).length > 0,\n emptyChallengeAnswersMessage,\n );\n return { challengeAnswers: answers as ChallengeAnswersByIndex };\n};\n\n/**\n * Lets publication.publishChallengeAnswers() take the hooks' input forms. Call it with every\n * CHALLENGE the publication receives: the publication is wrapped once, and the challenge indexes\n * used to map a deprecated array are those of the latest CHALLENGE.\n */\nexport const withPublishChallengeAnswersCompat = <T>(publication: T, challenge: Challenge): T => {\n const target = publication as Record<string | symbol, any> | undefined;\n if (!target || typeof target.publishChallengeAnswers !== \"function\") {\n return publication;\n }\n\n target[challengeIndexesKey] = getChallengeIndexes(challenge);\n if (target[publishChallengeAnswersCompatMarker]) {\n return publication;\n }\n\n const publishChallengeAnswers = target.publishChallengeAnswers.bind(publication);\n target.publishChallengeAnswers = async (challengeAnswers: ChallengeAnswersInput) =>\n publishChallengeAnswers(\n normalizeChallengeAnswersForPkc(challengeAnswers, target[challengeIndexesKey]),\n );\n target[publishChallengeAnswersCompatMarker] = true;\n\n return publication;\n};\n\nexport * from \"./protocol-compat\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkc-js-mock-content.d.ts","sourceRoot":"","sources":["../../../src/lib/pkc-js/pkc-js-mock-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pkc-js-mock-content.d.ts","sourceRoot":"","sources":["../../../src/lib/pkc-js/pkc-js-mock-content.ts"],"names":[],"mappings":"AAsgDA,QAAA,MAAM,SAAS,EAAE,GAEhB,CAAC;AAeF,eAAe,SAAS,CAAC"}
|
|
@@ -1059,10 +1059,11 @@ class Publication extends EventEmitter {
|
|
|
1059
1059
|
}
|
|
1060
1060
|
simulateChallengeEvent() {
|
|
1061
1061
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1062
|
-
|
|
1062
|
+
// keyed by challenge index, like pkc-js
|
|
1063
|
+
const challenges = {};
|
|
1063
1064
|
const challengeCount = yield getNumberBetween(1, 3, yield getNumberHash(this.challengeRequestId));
|
|
1064
|
-
|
|
1065
|
-
challenges
|
|
1065
|
+
for (let challengeIndex = 0; challengeIndex < challengeCount; challengeIndex++) {
|
|
1066
|
+
challenges[String(challengeIndex)] = { type: "image/png", challenge: captchaImageBase64 };
|
|
1066
1067
|
}
|
|
1067
1068
|
const challengeMessage = {
|
|
1068
1069
|
type: "CHALLENGE",
|
|
@@ -1072,7 +1073,7 @@ class Publication extends EventEmitter {
|
|
|
1072
1073
|
this.emit("challenge", challengeMessage, this);
|
|
1073
1074
|
});
|
|
1074
1075
|
}
|
|
1075
|
-
publishChallengeAnswers(
|
|
1076
|
+
publishChallengeAnswers(_options) {
|
|
1076
1077
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1077
1078
|
yield simulateLoadingTime();
|
|
1078
1079
|
this.simulateChallengeVerificationEvent();
|