@usethrottle/storefront-react 0.0.0-stage → 0.1.0
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/CLAUDE.md +67 -0
- package/README.md +119 -2
- package/dist/StorefrontProvider-Br4wUHui.d.cts +559 -0
- package/dist/StorefrontProvider-DLEPEjg6.d.ts +559 -0
- package/dist/account/index.cjs +69 -0
- package/dist/account/index.cjs.map +1 -0
- package/dist/account/index.d.cts +23 -0
- package/dist/account/index.d.ts +23 -0
- package/dist/account/index.js +68 -0
- package/dist/account/index.js.map +1 -0
- package/dist/chunk-2LCPIY2P.cjs +16 -0
- package/dist/chunk-2LCPIY2P.cjs.map +1 -0
- package/dist/chunk-3A72UY6T.js +2126 -0
- package/dist/chunk-3A72UY6T.js.map +1 -0
- package/dist/chunk-3JMIVAHN.js +185 -0
- package/dist/chunk-3JMIVAHN.js.map +1 -0
- package/dist/chunk-4J6AGWNC.cjs +24 -0
- package/dist/chunk-4J6AGWNC.cjs.map +1 -0
- package/dist/chunk-4U6MYDZV.js +17 -0
- package/dist/chunk-4U6MYDZV.js.map +1 -0
- package/dist/chunk-66HDJVPS.js +22 -0
- package/dist/chunk-66HDJVPS.js.map +1 -0
- package/dist/chunk-6X2OZSNV.cjs +83 -0
- package/dist/chunk-6X2OZSNV.cjs.map +1 -0
- package/dist/chunk-6ZMMZ245.cjs +2127 -0
- package/dist/chunk-6ZMMZ245.cjs.map +1 -0
- package/dist/chunk-7R37CVAB.cjs +23 -0
- package/dist/chunk-7R37CVAB.cjs.map +1 -0
- package/dist/chunk-A3IFWQUV.js +368 -0
- package/dist/chunk-A3IFWQUV.js.map +1 -0
- package/dist/chunk-AYC2YK4E.cjs +95 -0
- package/dist/chunk-AYC2YK4E.cjs.map +1 -0
- package/dist/chunk-AZV5U7YB.cjs +18 -0
- package/dist/chunk-AZV5U7YB.cjs.map +1 -0
- package/dist/chunk-CE2SKNQP.cjs +71 -0
- package/dist/chunk-CE2SKNQP.cjs.map +1 -0
- package/dist/chunk-D76CRI4X.js +2175 -0
- package/dist/chunk-D76CRI4X.js.map +1 -0
- package/dist/chunk-DOAII637.cjs +186 -0
- package/dist/chunk-DOAII637.cjs.map +1 -0
- package/dist/chunk-DYHHAOMG.cjs +17 -0
- package/dist/chunk-DYHHAOMG.cjs.map +1 -0
- package/dist/chunk-EYSVU5SJ.js +196 -0
- package/dist/chunk-EYSVU5SJ.js.map +1 -0
- package/dist/chunk-HSUUDZWS.js +37 -0
- package/dist/chunk-HSUUDZWS.js.map +1 -0
- package/dist/chunk-HZ6VEN6Q.cjs +101 -0
- package/dist/chunk-HZ6VEN6Q.cjs.map +1 -0
- package/dist/chunk-IJOTLGPT.js +16 -0
- package/dist/chunk-IJOTLGPT.js.map +1 -0
- package/dist/chunk-ISDATHVC.js +219 -0
- package/dist/chunk-ISDATHVC.js.map +1 -0
- package/dist/chunk-LW2A6USV.js +100 -0
- package/dist/chunk-LW2A6USV.js.map +1 -0
- package/dist/chunk-M4YXSLRG.cjs +369 -0
- package/dist/chunk-M4YXSLRG.cjs.map +1 -0
- package/dist/chunk-NDUEJJLP.cjs +2176 -0
- package/dist/chunk-NDUEJJLP.cjs.map +1 -0
- package/dist/chunk-NNE4FYRT.js +820 -0
- package/dist/chunk-NNE4FYRT.js.map +1 -0
- package/dist/chunk-NW3EFHY2.js +15 -0
- package/dist/chunk-NW3EFHY2.js.map +1 -0
- package/dist/chunk-NZRUQUN5.js +167 -0
- package/dist/chunk-NZRUQUN5.js.map +1 -0
- package/dist/chunk-P6HHE57S.cjs +38 -0
- package/dist/chunk-P6HHE57S.cjs.map +1 -0
- package/dist/chunk-PHY7AY27.cjs +197 -0
- package/dist/chunk-PHY7AY27.cjs.map +1 -0
- package/dist/chunk-PNJOFFTL.cjs +128 -0
- package/dist/chunk-PNJOFFTL.cjs.map +1 -0
- package/dist/chunk-PXZQ4ONA.js +127 -0
- package/dist/chunk-PXZQ4ONA.js.map +1 -0
- package/dist/chunk-Q3VTUBPP.js +82 -0
- package/dist/chunk-Q3VTUBPP.js.map +1 -0
- package/dist/chunk-Q3XFD5UI.js +45 -0
- package/dist/chunk-Q3XFD5UI.js.map +1 -0
- package/dist/chunk-QM7KTT7F.js +94 -0
- package/dist/chunk-QM7KTT7F.js.map +1 -0
- package/dist/chunk-RLWZOLXL.js +70 -0
- package/dist/chunk-RLWZOLXL.js.map +1 -0
- package/dist/chunk-SV53BRP2.js +23 -0
- package/dist/chunk-SV53BRP2.js.map +1 -0
- package/dist/chunk-VWXJO427.cjs +821 -0
- package/dist/chunk-VWXJO427.cjs.map +1 -0
- package/dist/chunk-WIIOJDHR.cjs +220 -0
- package/dist/chunk-WIIOJDHR.cjs.map +1 -0
- package/dist/chunk-XQHGFWLG.cjs +46 -0
- package/dist/chunk-XQHGFWLG.cjs.map +1 -0
- package/dist/chunk-ZHCXI2ZZ.cjs +168 -0
- package/dist/chunk-ZHCXI2ZZ.cjs.map +1 -0
- package/dist/index-RSj2Rg62.d.cts +8 -0
- package/dist/index-RSj2Rg62.d.ts +8 -0
- package/dist/index.cjs +2829 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1718 -0
- package/dist/index.d.ts +1718 -0
- package/dist/index.js +2828 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata-QhKw-tvz.d.cts +188 -0
- package/dist/metadata-QhKw-tvz.d.ts +188 -0
- package/dist/next/client.cjs +84 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.cts +40 -0
- package/dist/next/client.d.ts +40 -0
- package/dist/next/client.js +83 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/index.cjs +1090 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +218 -0
- package/dist/next/index.d.ts +218 -0
- package/dist/next/index.js +1049 -0
- package/dist/next/index.js.map +1 -0
- package/dist/server/index.cjs +994 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +229 -0
- package/dist/server/index.d.ts +229 -0
- package/dist/server/index.js +951 -0
- package/dist/server/index.js.map +1 -0
- package/dist/styles.css +2111 -0
- package/dist/use-part-DCfFk7kf.d.ts +24 -0
- package/dist/use-part-DgjPBL_O.d.cts +24 -0
- package/package.json +121 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/next/client.tsx","../../src/next/sync-client.ts"],"sourcesContent":["import NextLink from 'next/link.js';\nimport { usePathname, useRouter, useSearchParams } from 'next/navigation.js';\nimport { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { StorefrontProvider, type StorefrontProviderProps } from '../provider/StorefrontProvider';\nimport type { StorefrontRouter } from '../provider/router';\nimport type { LinkComponent } from '../link';\nimport { syncServerGeneration } from './sync-client';\n\nexport { syncServerGeneration } from './sync-client';\n\n/**\n * The props of `StorefrontNextProvider`: those of `StorefrontProvider` except the router, the link and `onGenerationChange`, which it supplies, plus `syncPath`.\n */\nexport type StorefrontNextProviderProps = Omit<StorefrontProviderProps, 'router' | 'linkComponent' | 'onGenerationChange'> & {\n /**\n * The route that clears the server's cache when the catalog changed (`createGenerationSyncHandler`).\n * Default `'/api/throttle/sync'`; `null` skips the POST and the refresh alone follows.\n */\n syncPath?: string | null;\n};\n\n// `.js` suffixes: `next` has no exports map, so native Node ESM (a plain import of this entry) needs the file name.\nconst Link: LinkComponent = ({ prefetch, ...anchor }) => <NextLink prefetch={prefetch} {...anchor} />;\n\ntype QuerySeen = { current: string | null };\n\n/**\n * Reads the URL's query for the provider. It renders nothing and has no children, and sits in its own\n * `<Suspense>`: on a statically rendered route `useSearchParams` suspends (client rendering up to the\n * nearest boundary), and that must stop here, not take the whole storefront tree with it (the server could\n * then neither send the page nor answer a 404). While it renders it leaves the query in `seen`; the body\n * renders after it, as its next sibling, so a render of the tree (on the server, in hydration, on a\n * navigation) always reads the query of the URL it renders for. `onChange` only makes the body render again\n * when the browser reads a query the server could not (a static route), or when only the query changed.\n */\nfunction SearchParamsBridge({ seen, onChange }: { seen: QuerySeen; onChange(query: string): void }) {\n const query = useSearchParams()?.toString() ?? '';\n seen.current = query;\n useEffect(() => onChange(query), [query, onChange]);\n return null;\n}\n\n/**\n * `StorefrontProvider` for the Next App Router: navigation through `useRouter`, `usePathname` and\n * `useSearchParams`, links through `next/link`, and, when the catalog's generation changes in an open\n * tab (`generationWatch`, every 60 s at the least, `false` to turn it off), a POST to `syncPath` and then\n * `router.refresh()`. The signed webhook (`createRevalidateHandler`) stays the primary path.\n *\n * The query comes from `useSearchParams`, read in a small component of its own inside a `<Suspense>`, so a\n * statically rendered route is sent with the whole tree (the query is empty until the browser reads the\n * URL; a product page then takes `?variant=` from it) and a missing page can still answer 404.\n */\nexport function StorefrontNextProvider(props: StorefrontNextProviderProps) {\n const seen = useRef<string | null>(null);\n const [read, setRead] = useState<string | null>(null);\n return (\n <>\n <Suspense fallback={null}>\n <SearchParamsBridge seen={seen} onChange={setRead} />\n </Suspense>\n <NextProviderBody {...props} seen={seen} read={read} />\n </>\n );\n}\n\nfunction NextProviderBody({\n syncPath = '/api/throttle/sync',\n seen,\n read,\n ...props\n}: StorefrontNextProviderProps & { seen: QuerySeen; read: string | null }) {\n const next = useRouter();\n const pathname = usePathname();\n // `seen` is the query of the URL being rendered (the bridge rendered just before this); `read` is only\n // what the browser reported, for the one case where the bridge could not render (a static route's first pass).\n const query = seen.current ?? read ?? '';\n const router = useMemo<StorefrontRouter>(\n () => ({\n pathname: pathname ?? '/',\n searchParams: new URLSearchParams(query),\n push: (href, options) => next.push(href, options),\n replace: (href, options) => next.replace(href, options),\n }),\n [next, pathname, query],\n );\n const onGenerationChange = useCallback(() => {\n void (async () => {\n if (syncPath !== null) await syncServerGeneration(syncPath);\n next.refresh();\n })();\n }, [next, syncPath]);\n return <StorefrontProvider {...props} router={router} linkComponent={Link} onGenerationChange={onGenerationChange} />;\n}\n","/** How long a throttled answer waits before the one more ask: the server's 5 s window plus a margin. */\nconst THROTTLED_RETRY_MS = 5100;\n/** The longest a deferred clearing is waited for (the server's window is 60 s). */\nconst MAX_RETRY_MS = 65_000;\n\n/**\n * Asks the server to check the catalog's generation and clear its cache if it moved, so the\n * `router.refresh()` that follows renders the change. A throttled answer (another tab or request read a\n * moment ago) is asked once more after 5100 ms. An answer with `retryAfterMs` (the change was found but\n * the minute's one clearing was spent) is asked once more after that long. Every failure resolves: the\n * refresh still happens.\n */\nexport async function syncServerGeneration(path: string): Promise<void> {\n const ask = async (): Promise<number | undefined> => {\n try {\n const response = await fetch(path, { method: 'POST', cache: 'no-store' });\n if (!response.ok) return undefined;\n const answer = (await response.json()) as { throttled?: boolean; retryAfterMs?: number } | null;\n if (typeof answer?.retryAfterMs === 'number') return Math.min(Math.max(answer.retryAfterMs, 0) + 100, MAX_RETRY_MS);\n return answer?.throttled === true ? THROTTLED_RETRY_MS : undefined;\n } catch {\n return undefined;\n }\n };\n const wait = await ask();\n if (wait !== undefined) {\n await new Promise<void>((resolve) => setTimeout(resolve, wait));\n await ask();\n }\n}\n"],"mappings":";;;;;;;;;AAAA,OAAO,cAAc;AACrB,SAAS,aAAa,WAAW,uBAAuB;AACxD,SAAS,UAAU,aAAa,WAAW,SAAS,QAAQ,gBAAgB;;;ACD5E,IAAM,qBAAqB;AAE3B,IAAM,eAAe;AASrB,eAAsB,qBAAqB,MAA6B;AACtE,QAAM,MAAM,YAAyC;AACnD,QAAI;AACF,YAAM,WAAW,MAAM,MAAM,MAAM,EAAE,QAAQ,QAAQ,OAAO,WAAW,CAAC;AACxE,UAAI,CAAC,SAAS,GAAI,QAAO;AACzB,YAAM,SAAU,MAAM,SAAS,KAAK;AACpC,UAAI,OAAO,QAAQ,iBAAiB,SAAU,QAAO,KAAK,IAAI,KAAK,IAAI,OAAO,cAAc,CAAC,IAAI,KAAK,YAAY;AAClH,aAAO,QAAQ,cAAc,OAAO,qBAAqB;AAAA,IAC3D,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,QAAM,OAAO,MAAM,IAAI;AACvB,MAAI,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