@pantheon-systems/pcc-react-sdk
Version:
Pantheon Content Cloud React SDK
1 lines • 17.4 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.ts","../src/hooks/use-article.ts","../src/hooks/use-articles.ts","../src/hooks/use-pagination.ts","../src/server/index.ts","../src/core/pantheon-api.ts","../src/core/pantheon-context.tsx","../src/utils/markdownConverter.ts"],"names":["index_exports","__export","GQL","PCCConvenienceFunctions","NextPantheonAPI","PantheonClient","PantheonProvider","findTab","flattenDocumentTabs","getAllTags","getArticle","getArticleBySlugOrId","getArticlePathComponentsFromContentStructure","getArticleURLFromSite","getArticleURLFromSiteWithOptions","getArticles","getPaginatedArticles","getRecommendedArticles","getSite","markdownToText","updateConfig","useArticle","useArticles","useMutation","usePagination","usePantheonClient","useQuery","useSubscription","id","args","apolloQueryOptions","related","_b","publishingLevel","contentType","buildContentType","memoizedArgs","useMemo","__spreadValues","_a","generateArticleQuery","__spreadProps","subscribeToMore","queryData","__objRest","useEffect","ARTICLE_UPDATE_SUBSCRIPTION","prev","subscriptionData","article","searchParams","LIST_ARTICLES_QUERY","convertSearchParamsToGQL","cursor","initialArticles","pageSize","currentCursor","setCurrentCursor","useState","articlePages","setArticlePages","fetching","setFetching","currentPage","setCurrentPage","__async","data","newCursor","result","server_exports","__reExport","types_star","options","api","PantheonAPI","req","res","isPagesRouterResponse","appRouterParams","headers","cookiesToObj","key","value","status","path","cookies","acc","cookie","PantheonContext","React","client","children","jsx","ApolloProvider","headerIdRegex","markdownHeaderSymbolRegex","parserConfig","markdown","markdownToTxt"],"mappings":"siFAAA,IAAAA,CAAAA,CAAA,GAAAC,CAAAD,CAAAA,CAAAA,CAAA,SAAAE,GAAA,CAAA,uBAAA,CAAA,IAAAC,wBAAA,WAAAC,CAAAA,IAAAA,CAAAA,CAAA,mBAAAC,cAAA,CAAA,gBAAA,CAAA,IAAAC,GAAA,OAAAC,CAAAA,IAAAA,OAAAA,CAAA,wBAAAC,mBAAA,CAAA,UAAA,CAAA,IAAAC,WAA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CAAO,CAAA,YAAA,CAEd,SAAAC,CACH,CAAA,CAAA,CACF,EAGWlE,EAAoB,CAAA,IAAM,CACrC,IAAMiE,CAAAA,CAASD,EAAM,UAAWD,CAAAA,CAAe,EAE/C,GAAI,CAACE,EACH,MAAM,IAAI,MAAM,0CAA0C,CAAA,CAG5D,OAAOA,CACT,EC9BMI,IAAAA,EAAAA,CAAgB,oBAChBC,EAA4B,CAAA,UAAA,CAC5BC,GAAe,CAAE,GAAA,CAAK,KAAM,MAAQ,CAAA,KAAM,EAEnC7E,EAAiB,CAAA,SAAU8E,EAAkB,CACxD,OAAOC,cACLD,CAAS,CAAA,OAAA,CAAQH,GAAe,EAAE,CAAA,CAClCE,EACF,CAAE,CAAA,OAAA,CAAQD,EAA2B,CAAA,EAAE,CACzC","file":"index.mjs","sourcesContent":["// Would be nice to have this as a separate entry point but\n// context is defined at module scope so can't be shared between\n// entry points.\n\n// https://github.com/facebook/react/issues/19541\nexport * from \"./hooks\";\n\nexport * from \"./server\";\nexport * from \"./core/pantheon-context\";\nexport * from \"./utils/markdownConverter\";\n","import { type QueryHookOptions } from \"@apollo/client\";\nimport { useQuery } from \"@apollo/client/react/hooks/useQuery.js\";\nimport {\n ARTICLE_UPDATE_SUBSCRIPTION,\n ArticleQueryArgs,\n buildContentType,\n generateArticleQuery,\n} from \"@pantheon-systems/pcc-sdk-core\";\nimport { Article } from \"@pantheon-systems/pcc-sdk-core/types\";\nimport { useEffect, useMemo } from \"react\";\n\ntype Return = ReturnType<typeof useQuery<{ article: Article }>> & {\n article: Article | undefined;\n};\n\ntype ApolloQueryOptions = Omit<\n QueryHookOptions<{ article: Article }>,\n \"variables\"\n>;\n\nexport const useArticle = (\n id: string,\n args?: ArticleQueryArgs,\n apolloQueryOptions?: ApolloQueryOptions,\n related?: {\n site?: boolean;\n },\n): Return => {\n const publishingLevel = args?.publishingLevel;\n const contentType = buildContentType(args?.contentType);\n\n const memoizedArgs = useMemo(() => {\n return {\n ...(publishingLevel && { publishingLevel }),\n ...(contentType && { contentType }),\n };\n }, [publishingLevel, contentType]);\n\n const { subscribeToMore, ...queryData } = useQuery<{ article: Article }>(\n generateArticleQuery({ withSite: related?.site }),\n {\n ...apolloQueryOptions,\n variables: { id, ...memoizedArgs },\n },\n );\n\n useEffect(() => {\n if (apolloQueryOptions?.skip) return;\n\n subscribeToMore({\n document: ARTICLE_UPDATE_SUBSCRIPTION,\n variables: { id, ...memoizedArgs },\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const { article } = subscriptionData.data;\n return { article, updatedAt: article.updatedAt };\n },\n });\n }, [id, memoizedArgs, subscribeToMore, apolloQueryOptions?.skip]);\n\n return {\n ...queryData,\n subscribeToMore,\n article: queryData.data?.article,\n };\n};\n","import { type QueryHookOptions } from \"@apollo/client\";\nimport { useQuery } from \"@apollo/client/react/hooks/useQuery.js\";\nimport {\n ArticleQueryArgs,\n ArticleSearchArgs,\n buildContentType,\n convertSearchParamsToGQL,\n LIST_ARTICLES_QUERY,\n} from \"@pantheon-systems/pcc-sdk-core\";\nimport { ArticleWithoutContent } from \"@pantheon-systems/pcc-sdk-core/types\";\n\ntype ListArticlesResponse = {\n articles: ArticleWithoutContent[];\n};\n\ntype Return = ReturnType<typeof useQuery<ListArticlesResponse>> & {\n articles: ArticleWithoutContent[] | undefined;\n};\n\ntype ApolloQueryOptions = Omit<\n QueryHookOptions<ListArticlesResponse>,\n \"variables\"\n>;\n\nexport const useArticles = (\n args?: ArticleQueryArgs,\n searchParams?: ArticleSearchArgs,\n apolloQueryOptions?: ApolloQueryOptions,\n): Return => {\n const contentType = buildContentType(args?.contentType);\n const queryData = useQuery<ListArticlesResponse>(LIST_ARTICLES_QUERY, {\n ...apolloQueryOptions,\n variables: {\n ...args,\n ...convertSearchParamsToGQL(searchParams),\n contentType,\n },\n });\n\n return {\n ...queryData,\n articles: queryData.data?.articles,\n };\n};\n","import { PCCConvenienceFunctions } from \"@pantheon-systems/pcc-sdk-core\";\nimport {\n ArticleWithoutContent,\n PaginatedArticle,\n} from \"@pantheon-systems/pcc-sdk-core/types\";\nimport { useEffect, useState } from \"react\";\n\ninterface Props {\n cursor?: string;\n pageSize: number;\n initialArticles?: PaginatedArticle[] | ArticleWithoutContent[];\n}\n\nexport function usePagination({ cursor, initialArticles, pageSize }: Props) {\n const [currentCursor, setCurrentCursor] = useState(cursor);\n const [articlePages, setArticlePages] = useState(\n initialArticles ? [initialArticles] : [],\n );\n const [fetching, setFetching] = useState(false);\n const [currentPage, setCurrentPage] = useState(0);\n\n useEffect(() => {\n (async () => {\n if (articlePages[currentPage]) return;\n\n setFetching(true);\n const { data, cursor: newCursor } =\n await PCCConvenienceFunctions.getPaginatedArticles({\n pageSize,\n ...(currentCursor && { cursor: currentCursor }),\n });\n setFetching(false);\n setArticlePages((prev) => {\n const result = [...prev];\n result[currentPage] = data;\n return result;\n });\n setCurrentCursor(newCursor);\n })();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentPage]);\n\n return {\n // Return last page if current page doesn't exist\n data: articlePages[currentPage] || articlePages[articlePages.length - 1],\n fetching,\n onPageChange: setCurrentPage,\n currentPage,\n };\n}\n","export type {\n PantheonClientConfig,\n PantheonAPIOptions,\n} from \"@pantheon-systems/pcc-sdk-core\";\nexport { PantheonClient } from \"@pantheon-systems/pcc-sdk-core\";\n\nexport {\n getArticles,\n getPaginatedArticles,\n getRecommendedArticles,\n getArticle,\n getAllTags,\n getArticleBySlugOrId,\n PCCConvenienceFunctions,\n getArticlePathComponentsFromContentStructure,\n getArticleURLFromSite,\n getArticleURLFromSiteWithOptions,\n updateConfig,\n GQL,\n getSite,\n findTab,\n flattenDocumentTabs,\n} from \"@pantheon-systems/pcc-sdk-core\";\nexport * from \"@pantheon-systems/pcc-sdk-core/types\";\n\nexport { NextPantheonAPI as PantheonAPI } from \"../core/pantheon-api\";\n","import {\n PantheonAPI,\n PantheonAPIOptions,\n} from \"@pantheon-systems/pcc-sdk-core\";\nimport type { NextApiRequest, NextApiResponse } from \"next\";\nimport type { NextRequest } from \"next/server\";\n\nexport interface AppRouterParams {\n params: Record<string, string>;\n headers?: null;\n}\n\ntype Handler = {\n // In Pages routing, req and res are NextApiRequest and NextApiResponse\n (req: NextApiRequest, res: NextApiResponse): Promise<unknown>;\n // In App routing, req is NextRequest and the second argument is AppRouterParams\n (req: NextRequest, res: AppRouterParams): Promise<void | Response>;\n};\n\nexport function NextPantheonAPI(options?: PantheonAPIOptions) {\n const api = PantheonAPI(options);\n\n const handler: Handler = async (req, res) => {\n if (isPagesRouterResponse(res)) {\n // Pages router\n // Intentionally voiding the return value, page router API routes should not return a value\n // https://github.com/vercel/next.js/discussions/48951\n return void (await api(req as NextApiRequest, res as NextApiResponse));\n }\n\n // App router\n const appRouterParams = res as AppRouterParams;\n const headers = new Headers({\n ...(appRouterParams.headers || {}),\n });\n\n return (await api(\n {\n query: {\n ...Object.fromEntries((req as NextRequest).nextUrl.searchParams),\n ...appRouterParams.params,\n },\n cookies: cookiesToObj((req as NextRequest).cookies),\n },\n {\n getHeader: (key) => headers.get(key) || \"\",\n setHeader: (key, value) => headers.set(key, value.toString()),\n redirect: (status, path) => {\n headers.set(\"Location\", path);\n return new Response(null, {\n status,\n headers,\n });\n },\n json: (data) => {\n return Response.json(data, {\n headers,\n });\n },\n },\n )) as void | Response;\n };\n\n return handler;\n}\n\nfunction isPagesRouterResponse(\n res: AppRouterParams | NextApiResponse,\n): res is NextApiResponse {\n // We can differentiate between app router vs pages api\n // by checking for params\n // reference: (https://github.com/nextauthjs/next-auth/blob/v4/packages/next-auth/src/next/index.ts)\n return res != null && typeof res === \"object\" && !(\"params\" in res);\n}\n\nfunction cookiesToObj(cookies: NextRequest[\"cookies\"]) {\n // Convert to name value pairs\n return cookies.getAll().reduce(\n (acc, cookie) => {\n acc[cookie.name] = cookie.value;\n return acc;\n },\n {} as Record<string, string>,\n );\n}\n","import { ApolloClient } from \"@apollo/client/core/ApolloClient.js\";\nimport { ApolloProvider } from \"@apollo/client/react/context/ApolloProvider.js\";\nimport { PantheonClient } from \"@pantheon-systems/pcc-sdk-core\";\nimport React, { PropsWithChildren } from \"react\";\n\ninterface PantheonProviderProps extends PropsWithChildren<object> {\n client: PantheonClient;\n}\n\nconst PantheonContext = React.createContext<PantheonClient | null>(null);\n\nexport const PantheonProvider = ({\n client,\n children,\n}: PantheonProviderProps) => (\n <PantheonContext.Provider value={client}>\n <ApolloProvider\n client={client.apolloClient as unknown as ApolloClient<unknown>}\n >\n {children}\n </ApolloProvider>\n </PantheonContext.Provider>\n);\n\nexport const usePantheonClient = () => {\n const client = React.useContext(PantheonContext);\n\n if (!client) {\n throw new Error(\"Cannot use outside of a PantheonProvider\");\n }\n\n return client;\n};\n","import { markdownToTxt } from \"markdown-to-txt\";\n\nconst headerIdRegex = /\\s*\\{#h\\.[^}]*\\}/g;\nconst markdownHeaderSymbolRegex = /^#+\\s*/gm;\nconst parserConfig = { gfm: true, mangle: false };\n\nexport const markdownToText = function (markdown: string) {\n return markdownToTxt(\n markdown.replace(headerIdRegex, \"\"),\n parserConfig,\n ).replace(markdownHeaderSymbolRegex, \"\");\n};\n"]}