@tappify/extension-sdk 2.0.0 → 2.1.0-beta.2
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/README.md +208 -0
- package/dist/chunk-2CY5HVY7.mjs +59 -0
- package/dist/chunk-2CY5HVY7.mjs.map +1 -0
- package/dist/{chunk-2DBSVKAU.cjs → chunk-6HETNZJY.cjs} +1 -1
- package/dist/chunk-6HETNZJY.cjs.map +1 -0
- package/dist/{chunk-PYJMJF44.cjs → chunk-7YKH4LZN.cjs} +9 -2
- package/dist/chunk-7YKH4LZN.cjs.map +1 -0
- package/dist/{chunk-RMUWRESK.cjs → chunk-A74HCO6T.cjs} +31 -18
- package/dist/chunk-A74HCO6T.cjs.map +1 -0
- package/dist/chunk-BPCGXXMD.cjs +781 -0
- package/dist/chunk-BPCGXXMD.cjs.map +1 -0
- package/dist/chunk-EB5XWQAU.cjs +132 -0
- package/dist/chunk-EB5XWQAU.cjs.map +1 -0
- package/dist/{chunk-5AAPD5WV.cjs → chunk-GAUZYBXE.cjs} +11 -11
- package/dist/chunk-GAUZYBXE.cjs.map +1 -0
- package/dist/chunk-J5LGTIGS.mjs +10 -0
- package/dist/chunk-J5LGTIGS.mjs.map +1 -0
- package/dist/{chunk-ZT35X7KL.mjs → chunk-KZ5NGFUP.mjs} +22 -9
- package/dist/chunk-KZ5NGFUP.mjs.map +1 -0
- package/dist/chunk-NN263PGQ.cjs +70 -0
- package/dist/chunk-NN263PGQ.cjs.map +1 -0
- package/dist/{chunk-3YWVYA42.cjs → chunk-O357OJXL.cjs} +14 -18
- package/dist/chunk-O357OJXL.cjs.map +1 -0
- package/dist/chunk-ONJMPO3P.cjs +59 -0
- package/dist/chunk-ONJMPO3P.cjs.map +1 -0
- package/dist/{chunk-OPPYEA7F.cjs → chunk-PRCZMOLD.cjs} +3 -3
- package/dist/chunk-PRCZMOLD.cjs.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +10 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/{chunk-QHM7XNRK.mjs → chunk-QA5AL3VZ.mjs} +2 -2
- package/dist/{chunk-QHM7XNRK.mjs.map → chunk-QA5AL3VZ.mjs.map} +1 -1
- package/dist/chunk-QJMZRV7A.mjs +132 -0
- package/dist/chunk-QJMZRV7A.mjs.map +1 -0
- package/dist/{chunk-CSTYBKZC.mjs → chunk-QXD7WVKK.mjs} +1 -1
- package/dist/chunk-QXD7WVKK.mjs.map +1 -0
- package/dist/{chunk-4C5Z3CIK.mjs → chunk-RBIQT75L.mjs} +2 -2
- package/dist/chunk-RBIQT75L.mjs.map +1 -0
- package/dist/{chunk-MNDVYPEP.mjs → chunk-SGCYEEXD.mjs} +9 -2
- package/dist/chunk-SGCYEEXD.mjs.map +1 -0
- package/dist/{chunk-BDCX6LRQ.mjs → chunk-SGEYDV3K.mjs} +3 -3
- package/dist/chunk-SGEYDV3K.mjs.map +1 -0
- package/dist/{chunk-IGK2AP6J.mjs → chunk-SLGOHIBL.mjs} +13 -17
- package/dist/chunk-SLGOHIBL.mjs.map +1 -0
- package/dist/chunk-SWG7CNTZ.mjs +781 -0
- package/dist/chunk-SWG7CNTZ.mjs.map +1 -0
- package/dist/{chunk-7KIKOH5H.cjs → chunk-VV7ELNRW.cjs} +3 -3
- package/dist/chunk-VV7ELNRW.cjs.map +1 -0
- package/dist/chunk-Z43DPNZ6.mjs +70 -0
- package/dist/chunk-Z43DPNZ6.mjs.map +1 -0
- package/dist/client-BO3kavn0.d.ts +25 -0
- package/dist/client-DE-vMgdO.d.cts +25 -0
- package/dist/codegen.cjs.map +1 -1
- package/dist/codegen.d.cts +43 -7
- package/dist/codegen.d.ts +43 -7
- package/dist/codegen.mjs.map +1 -1
- package/dist/{constants-DJ_KgZpN.d.cts → constants-Bh759FUI.d.cts} +44 -8
- package/dist/{constants-DJ_KgZpN.d.ts → constants-Bh759FUI.d.ts} +44 -8
- package/dist/{context-Dt6xh_5t.d.cts → context-DI0EJCRD.d.cts} +5 -4
- package/dist/{context-Ml7k_V14.d.ts → context-mr8R5CNt.d.ts} +5 -4
- package/dist/{errors-COsBh7kd.d.cts → errors-Cqh0wrqt.d.cts} +3 -2
- package/dist/{errors-COsBh7kd.d.ts → errors-Cqh0wrqt.d.ts} +3 -2
- package/dist/host.cjs +5 -4
- package/dist/host.cjs.map +1 -1
- package/dist/host.d.cts +5 -5
- package/dist/host.d.ts +5 -5
- package/dist/host.mjs +4 -3
- package/dist/host.mjs.map +1 -1
- package/dist/index.cjs +9 -656
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -627
- package/dist/index.d.ts +69 -627
- package/dist/index.mjs +5 -652
- package/dist/index.mjs.map +1 -1
- package/dist/manifest.cjs +142 -86
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.d.cts +97 -12
- package/dist/manifest.d.ts +97 -12
- package/dist/manifest.mjs +129 -73
- package/dist/manifest.mjs.map +1 -1
- package/dist/server.cjs +15 -66
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +6 -6
- package/dist/server.d.ts +6 -6
- package/dist/server.mjs +10 -61
- package/dist/server.mjs.map +1 -1
- package/dist/testing/index.cjs +73 -750
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +30 -11
- package/dist/testing/index.d.ts +30 -11
- package/dist/testing/index.mjs +89 -766
- package/dist/testing/index.mjs.map +1 -1
- package/dist/testing/jest.cjs +6 -5
- package/dist/testing/jest.cjs.map +1 -1
- package/dist/testing/jest.mjs +3 -2
- package/dist/testing/jest.mjs.map +1 -1
- package/dist/testing/vitest.cjs +6 -5
- package/dist/testing/vitest.cjs.map +1 -1
- package/dist/testing/vitest.d.cts +10 -0
- package/dist/testing/vitest.d.ts +10 -0
- package/dist/testing/vitest.mjs +3 -2
- package/dist/testing/vitest.mjs.map +1 -1
- package/dist/{types-DDAGLpov.d.ts → types-BdDaLnqs.d.cts} +4 -3
- package/dist/{types-DrpQSv_2.d.cts → types-uGHrRaOj.d.ts} +4 -3
- package/dist/ui/styles.css +740 -0
- package/dist/ui.cjs +1018 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +231 -0
- package/dist/ui.d.ts +231 -0
- package/dist/ui.mjs +1018 -0
- package/dist/ui.mjs.map +1 -0
- package/dist/vite-preview-bootstrap.cjs +66 -0
- package/dist/vite-preview-bootstrap.cjs.map +1 -0
- package/dist/vite-preview-bootstrap.d.cts +15 -0
- package/dist/vite-preview-bootstrap.d.ts +15 -0
- package/dist/vite-preview-bootstrap.mjs +66 -0
- package/dist/vite-preview-bootstrap.mjs.map +1 -0
- package/dist/vite-preview.cjs +876 -0
- package/dist/vite-preview.cjs.map +1 -0
- package/dist/vite-preview.d.cts +9 -0
- package/dist/vite-preview.d.ts +9 -0
- package/dist/vite-preview.mjs +876 -0
- package/dist/vite-preview.mjs.map +1 -0
- package/dist/vite.cjs +320 -60
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +54 -8
- package/dist/vite.d.ts +54 -8
- package/dist/vite.mjs +312 -54
- package/dist/vite.mjs.map +1 -1
- package/dist/work-events-BlOVpK0k.d.ts +547 -0
- package/dist/work-events-D97EoqvS.d.cts +547 -0
- package/package.json +19 -2
- package/schema/extension-v2.json +440 -121
- package/dist/chunk-2DBSVKAU.cjs.map +0 -1
- package/dist/chunk-3YWVYA42.cjs.map +0 -1
- package/dist/chunk-4C5Z3CIK.mjs.map +0 -1
- package/dist/chunk-5AAPD5WV.cjs.map +0 -1
- package/dist/chunk-7KIKOH5H.cjs.map +0 -1
- package/dist/chunk-BDCX6LRQ.mjs.map +0 -1
- package/dist/chunk-CSTYBKZC.mjs.map +0 -1
- package/dist/chunk-IGK2AP6J.mjs.map +0 -1
- package/dist/chunk-MNDVYPEP.mjs.map +0 -1
- package/dist/chunk-OPPYEA7F.cjs.map +0 -1
- package/dist/chunk-PYJMJF44.cjs.map +0 -1
- package/dist/chunk-RMUWRESK.cjs.map +0 -1
- package/dist/chunk-ZT35X7KL.mjs.map +0 -1
- package/dist/handler-CZIlZ5vu.d.ts +0 -227
- package/dist/handler-kU9Jf36K.d.cts +0 -227
- package/dist/styles.css +0 -367
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/hooks.ts","../src/client/query.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\nimport { useTap } from './context';\nimport type { Tap, TapChangeKey, TapFilters, TapSize } from './types';\n\nfunction useTapSlice<T>(key: TapChangeKey, select: (tap: Tap) => T): T {\n const tap = useTap();\n\n const subscribe = useCallback(\n (listener: () => void) => tap.__subscribe(key, listener),\n [tap, key],\n );\n const snapshot = useCallback(() => select(tap), [tap, select]);\n\n return useSyncExternalStore(subscribe, snapshot, snapshot);\n}\n\nconst selectAuth = (tap: Tap): Tap['auth'] => tap.auth;\nconst selectProject = (tap: Tap): Tap['project'] => tap.project;\nconst selectFilters = (tap: Tap): TapFilters => tap.filters;\nconst selectTheme = (tap: Tap): Tap['theme'] => tap.theme;\nconst selectSize = (tap: Tap): TapSize => tap.ui.size;\nconst selectParams = (tap: Tap): Record<string, string> => tap.params;\nconst selectContext = (tap: Tap): Record<string, unknown> => tap.context;\n\n/**\n * Returns the install token, the signed-in teammate, the workspace id, the\n * granted scopes and `can(scope)`.\n *\n * @remarks\n * Re-renders the component when the host rotates the install token, and when the\n * signed-in teammate's role arrives after the mount. `scopes` and `can` report the\n * grant the mount was built with. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapAuth } from '@tappify/extension-sdk';\n * import { EmptyState } from '@tappify/extension-sdk/ui';\n *\n * function RevenuePanel() {\n * const auth = useTapAuth();\n * if (!auth.can('revenue:read')) {\n * return <EmptyState title=\"Revenue is not shared with this extension\" />;\n * }\n * return <span>Signed in as {auth.user.id}</span>;\n * }\n * ```\n */\nexport function useTapAuth(): Tap['auth'] {\n return useTapSlice('auth', selectAuth);\n}\n\n/**\n * Returns the project the mount renders in, with its apps, releases and tracked\n * keywords.\n *\n * @remarks\n * Re-renders when the host loads or reloads the project. Throws\n * `TAP_OUTSIDE_HOST` outside a mount. An extension installed on the workspace\n * rather than a project still renders inside one project at a time.\n *\n * @example\n * ```tsx\n * import { useTapProject } from '@tappify/extension-sdk';\n *\n * function Platforms() {\n * const project = useTapProject();\n * return <span>{project.name} ships to {project.platforms.join(' and ')}</span>;\n * }\n * ```\n */\nexport function useTapProject(): Tap['project'] {\n return useTapSlice('project', selectProject);\n}\n\n/**\n * Returns the date range, platform and country the owner's filter bar is set to.\n *\n * @remarks\n * Re-renders on every filter change, which is how a surface follows the owner's\n * picker. Pass `range` into a `series`, `reviews`, `crashes` or `revenue` query\n * yourself; the host adds only the country to a data read, while a procedure call\n * carries all three. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapFilters, useTapQuery } from '@tappify/extension-sdk';\n *\n * function Downloads() {\n * const filters = useTapFilters();\n * const downloads = useTapQuery({\n * kind: 'series',\n * metric: 'downloads',\n * range: filters.range,\n * });\n * return <span>{downloads.data?.points.length ?? 0} days</span>;\n * }\n * ```\n */\nexport function useTapFilters(): TapFilters {\n return useTapSlice('filters', selectFilters);\n}\n\n/**\n * Returns the mode the host is drawing in, as `{ mode: 'light' | 'dark' }`.\n *\n * @remarks\n * Re-renders when the owner switches theme. The host's CSS variables already\n * follow the theme, so reach for this only where a component has to branch in\n * code rather than restyle, such as a chart's series colours. Throws\n * `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapTheme } from '@tappify/extension-sdk';\n *\n * function SeriesLine() {\n * const theme = useTapTheme();\n * const stroke = theme.mode === 'dark' ? '#a5b4fc' : '#4f46e5';\n * return <svg><line x1=\"0\" y1=\"0\" x2=\"40\" y2=\"10\" stroke={stroke} /></svg>;\n * }\n * ```\n */\nexport function useTapTheme(): Tap['theme'] {\n return useTapSlice('theme', selectTheme);\n}\n\n/**\n * Returns how much room the mount has: `slot`, `panel` or `page`.\n *\n * @remarks\n * Expanding a widget mounts a second copy of the component in the panel rather\n * than resizing the one in the slot, so the change this hook reports is the\n * panel's own Widen and Narrow toggle moving between `panel` and `page`. Size\n * against the mount with a container query where CSS can do the work; this hook is\n * for the cases that need different markup. Throws `TAP_OUTSIDE_HOST` outside a\n * mount.\n *\n * @example\n * ```tsx\n * import { useTapSize } from '@tappify/extension-sdk';\n * import {\n * Table,\n * TableBody,\n * TableCell,\n * TableHead,\n * TableHeader,\n * TableRow,\n * } from '@tappify/extension-sdk/ui';\n *\n * function Keywords({ rows }: { rows: { term: string }[] }) {\n * const size = useTapSize();\n * const shown = size === 'slot' ? rows.slice(0, 3) : rows;\n * return (\n * <Table>\n * <TableHeader>\n * <TableRow variant=\"header\"><TableHead>Term</TableHead></TableRow>\n * </TableHeader>\n * <TableBody>\n * {shown.map(row => (\n * <TableRow key={row.term}><TableCell>{row.term}</TableCell></TableRow>\n * ))}\n * </TableBody>\n * </Table>\n * );\n * }\n * ```\n */\nexport function useTapSize(): TapSize {\n return useTapSlice('size', selectSize);\n}\n\n/**\n * Returns the route of the extension's own page: the page id, the whole sub-path,\n * and one key per segment.\n *\n * @remarks\n * The host builds `pageId`, `path` and then `0`, `1` and so on, one per segment of\n * the sub-path. Only a page entry is routed, so this is empty for a widget, a tab,\n * a row action and a settings panel. Re-renders when the owner navigates inside the\n * page. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapParams } from '@tappify/extension-sdk';\n *\n * function FunnelDetail() {\n * const params = useTapParams();\n * const funnelId = params['1'];\n * return <span>{funnelId ?? params.path}</span>;\n * }\n * ```\n */\nexport function useTapParams(): Record<string, string> {\n return useTapSlice('params', selectParams);\n}\n\n/**\n * Returns what the surface handed the mount: the payload Expand carried in, or\n * the row behind a row action.\n *\n * @remarks\n * Re-renders when the host hands the mount a new context. A row action reads the\n * row from its own `row` prop as well; this hook is the same value for a\n * component further down the tree. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapContext } from '@tappify/extension-sdk';\n *\n * function ContextNote() {\n * const context = useTapContext();\n * const reviewId = context.reviewId;\n * return <span>{typeof reviewId === 'string' ? reviewId : 'No review'}</span>;\n * }\n * ```\n */\nexport function useTapContext(): Record<string, unknown> {\n return useTapSlice('context', selectContext);\n}\n\n/**\n * Returns one value from the in-memory store every mount of the install shares,\n * with a setter for it.\n *\n * @remarks\n * The value is `undefined` until something sets it, and setting it re-renders\n * every mount reading the same key, including a sibling widget and the expand\n * panel. The store lives in the browser session: it is not persisted, not shared\n * between teammates or tabs, and never reaches Tappify or your server — use\n * `useTapStorage` for a value that has to come back tomorrow. Throws\n * `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapState } from '@tappify/extension-sdk';\n * import { Button } from '@tappify/extension-sdk/ui';\n *\n * function StepPicker() {\n * const [step, setStep] = useTapState<string>('selectedStep');\n * return (\n * <Button onClick={() => setStep('install')}>\n * {step ?? 'Pick a step'}\n * </Button>\n * );\n * }\n * ```\n */\nexport function useTapState<T>(\n key: string,\n): [T | undefined, (value: T) => void] {\n const tap = useTap();\n\n const subscribe = useCallback(\n (listener: () => void) => tap.__subscribe(`state:${key}`, listener),\n [tap, key],\n );\n const snapshot = useCallback(() => tap.state.get<T>(key), [tap, key]);\n const set = useCallback(\n (value: T) => {\n tap.state.set(key, value);\n },\n [tap, key],\n );\n\n const value = useSyncExternalStore(subscribe, snapshot, snapshot);\n return [value, set];\n}\n","import {\n useQuery,\n useQueryClient,\n type QueryClient,\n} from '@tanstack/react-query';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useTap } from './context';\nimport { TapError } from './errors';\nimport { useTapFilters } from './hooks';\nimport type {\n Tap,\n TapFilters,\n TapHostEvents,\n TapProcedureInput,\n TapProcedureName,\n TapProcedureOutput,\n TapQuery,\n TapResult,\n TapSingleton,\n TapSingletonDocument,\n TapSingletonName,\n} from './types';\n\nconst STALE_TIME_MS = 30_000;\n\n/** The third argument of `useTapQuery` and `useTapServer`. */\nexport interface TapQueryOptions {\n /** Holds the call back while this is `false`. Defaults to `true`. */\n enabled?: boolean;\n /** Tappify events that mark this result stale and refetch it when they arrive. */\n invalidateOn?: (keyof TapHostEvents)[];\n}\n\n/** What `useTapQuery` and `useTapServer` return. */\nexport interface TapQueryResult<T> {\n /**\n * `undefined` until the first answer for this key arrives. A later call that\n * fails leaves the last answer in place and only sets `error`, so branch on\n * `error` to detect a failure, never on `data`.\n */\n data: T | undefined;\n error: Error | null;\n /** `true` only while the first answer for this key is in flight. */\n isLoading: boolean;\n /** Asks again now, whether or not the cached answer has gone stale. */\n refetch(): void;\n}\n\n/** What `useTapStorage` returns: a read of the document, plus the two writes. */\nexport interface TapStorageResult<T> extends TapQueryResult<T | null> {\n /** Replaces the whole document. */\n save(document: T): Promise<void>;\n /** Merges the fields in and resolves to the merged document. */\n patch(partial: Partial<T>): Promise<T>;\n}\n\n/**\n * Builds the cache key `useTapQuery` reads a Tappify data query under.\n *\n * @remarks\n * The key carries the install, the query and the filters behind it, so two mounts\n * asking for the same numbers share one request. Call it only to reach the query\n * cache directly; the hooks build their own keys.\n *\n * @example\n * ```ts\n * import { dataQueryKey } from '@tappify/extension-sdk';\n *\n * const key = dataQueryKey('ins_test', { kind: 'keywords' }, {\n * range: { from: '2026-09-01', to: '2026-09-08' },\n * platform: 'all',\n * country: 'all',\n * });\n * ```\n */\nexport function dataQueryKey(\n installId: string,\n query: TapQuery,\n filters: TapFilters,\n): unknown[] {\n return ['ext', installId, 'data', query, filters];\n}\n\n/**\n * Builds the cache key `useTapServer` reads one procedure call under.\n *\n * @remarks\n * The input and the filters are part of the key, so the same procedure called\n * with different input caches separately. Call it only to reach the query cache\n * directly.\n *\n * @example\n * ```ts\n * import { procedureQueryKey } from '@tappify/extension-sdk';\n *\n * const key = procedureQueryKey('ins_test', 'getSummary', { days: 7 }, {\n * range: { from: '2026-09-01', to: '2026-09-08' },\n * platform: 'all',\n * country: 'all',\n * });\n * ```\n */\nexport function procedureQueryKey(\n installId: string,\n name: string,\n input: unknown,\n filters: TapFilters,\n): unknown[] {\n return ['ext', installId, 'proc', name, input, filters];\n}\n\n/**\n * Builds the cache key `useTapStorage` reads one collection's document under.\n *\n * @remarks\n * The filters are not part of the key, because a stored document does not depend\n * on them. Call it only to reach the query cache directly.\n *\n * @example\n * ```ts\n * import { storageQueryKey } from '@tappify/extension-sdk';\n *\n * const key = storageQueryKey('ins_test', 'preferences');\n * ```\n */\nexport function storageQueryKey(\n installId: string,\n collection: string,\n): unknown[] {\n return ['ext', installId, 'storage', collection];\n}\n\n/**\n * Builds the key prefix every cached answer of one install sits under.\n *\n * @remarks\n * This is the prefix `tap.invalidate()` with no name invalidates.\n *\n * @example\n * ```ts\n * import { installPrefix } from '@tappify/extension-sdk';\n *\n * const prefix = installPrefix('ins_test');\n * ```\n */\nexport function installPrefix(installId: string): unknown[] {\n return ['ext', installId];\n}\n\n/**\n * Builds the key prefix every cached call of one procedure sits under, whatever\n * its input.\n *\n * @remarks\n * This is the prefix `tap.invalidate(name)` invalidates.\n *\n * @example\n * ```ts\n * import { procedurePrefix } from '@tappify/extension-sdk';\n *\n * const prefix = procedurePrefix('ins_test', 'getSummary');\n * ```\n */\nexport function procedurePrefix(installId: string, name: string): unknown[] {\n return ['ext', installId, 'proc', name];\n}\n\nfunction useInvalidateOn(\n tap: Tap,\n client: QueryClient,\n queryKey: unknown[],\n events: (keyof TapHostEvents)[] | undefined,\n): void {\n const eventsRef = useRef(events);\n const keyRef = useRef(queryKey);\n\n useEffect(() => {\n eventsRef.current = events;\n keyRef.current = queryKey;\n });\n\n const eventSignature = (events ?? []).join(',');\n\n useEffect(() => {\n const names = eventsRef.current ?? [];\n if (names.length === 0) return;\n\n const unsubscribes = names.map(name =>\n tap.data.subscribe(name, () => {\n void client.invalidateQueries({ queryKey: keyRef.current });\n }),\n );\n\n return () => {\n for (const unsubscribe of unsubscribes) unsubscribe();\n };\n }, [tap, client, eventSignature]);\n}\n\nfunction useHostQueryClient(): QueryClient {\n try {\n return useQueryClient();\n } catch {\n throw new TapError(\n 'TAP_NO_QUERY_CLIENT',\n 'The Tappify host provides the query client. This hook runs only inside a Tappify mount — render the component from an entry declared in tappify.extension.json, or wrap it in renderWithTap() from @tappify/extension-sdk/testing.',\n );\n }\n}\n\n/**\n * Reads one query's worth of the owner's Tappify data, cached per install, query\n * and filter bar.\n *\n * @remarks\n * Each kind needs its own scope — `project` needs `projects:read`, `series` needs\n * `analytics:read`, `keywords` and `listing` need `store.metadata:read`, and\n * `reviews`, `crashes` and `revenue` need their own. A kind the install has not\n * granted comes back as a `TapError` with code `TAP_SCOPE_MISSING` in `error`. An\n * answer stays fresh for 30 seconds and a failed read is not retried, so\n * `refetch` is yours to call. The host adds only the country filter to the read:\n * pass `range` into a `series`, `reviews`, `crashes` or `revenue` query yourself,\n * and `platform` into a `series` query, which is the only kind that takes one.\n * Throws `TAP_NO_QUERY_CLIENT` when no Tappify mount provides the query client.\n *\n * @example\n * ```tsx\n * import { useTapFilters, useTapQuery } from '@tappify/extension-sdk';\n * import { Metric } from '@tappify/extension-sdk/ui';\n *\n * function Downloads() {\n * const filters = useTapFilters();\n * const downloads = useTapQuery(\n * { kind: 'series', metric: 'downloads', range: filters.range },\n * { invalidateOn: ['release.shipped'] },\n * );\n * const points = downloads.data?.points ?? [];\n * const total = points.reduce((sum, point) => sum + point.value, 0);\n * return <Metric label=\"Downloads\" value={total} />;\n * }\n * ```\n *\n * @example\n * ```tsx\n * import { useTapQuery } from '@tappify/extension-sdk';\n * import {\n * Table,\n * TableBody,\n * TableCell,\n * TableHead,\n * TableHeader,\n * TableRow,\n * } from '@tappify/extension-sdk/ui';\n *\n * function Keywords() {\n * const keywords = useTapQuery({ kind: 'keywords' });\n * return (\n * <Table>\n * <TableHeader>\n * <TableRow variant=\"header\">\n * <TableHead>Term</TableHead>\n * <TableHead>Rank</TableHead>\n * </TableRow>\n * </TableHeader>\n * <TableBody>\n * {(keywords.data?.keywords ?? []).map(keyword => (\n * <TableRow key={keyword.id}>\n * <TableCell>{keyword.term}</TableCell>\n * <TableCell>{keyword.position}</TableCell>\n * </TableRow>\n * ))}\n * </TableBody>\n * </Table>\n * );\n * }\n * ```\n */\nexport function useTapQuery<Q extends TapQuery>(\n query: Q,\n options: TapQueryOptions = {},\n): TapQueryResult<TapResult<Q>> {\n const tap = useTap();\n const client = useHostQueryClient();\n const filters = useTapFilters();\n const queryKey = dataQueryKey(tap.extension.installId, query, filters);\n\n const result = useQuery({\n queryKey,\n queryFn: () => tap.data.query(query),\n enabled: options.enabled ?? true,\n staleTime: STALE_TIME_MS,\n retry: false,\n });\n\n useInvalidateOn(tap, client, queryKey, options.invalidateOn);\n\n const resultRefetch = result.refetch;\n const refetch = useCallback(() => {\n void resultRefetch();\n }, [resultRefetch]);\n\n return {\n data: result.data,\n error: result.error,\n isLoading: result.isLoading,\n refetch,\n };\n}\n\n/**\n * Calls one procedure on your own server, cached per install, name, input and\n * filter bar.\n *\n * @remarks\n * The name and the input are narrowed by the `TapProcedureMap` augmentation\n * `tappify extension types` writes, so a procedure the manifest does not declare\n * does not compile; at runtime a name the host has no route for throws\n * `TAP_UNKNOWN_PROCEDURE`. The call carries the whole filter bar for you. An\n * answer stays fresh for 30 seconds and a failure is not retried; an error your\n * server threw arrives as a `TapServerError` with your own `code`. Throws\n * `TAP_NO_QUERY_CLIENT` when no Tappify mount provides the query client.\n *\n * @example\n * ```tsx\n * import { useTapFilters, useTapServer } from '@tappify/extension-sdk';\n * import { Button, ErrorState } from '@tappify/extension-sdk/ui';\n *\n * function Summary() {\n * const filters = useTapFilters();\n * const summary = useTapServer(\n * 'getSummary',\n * { days: 7, platform: filters.platform },\n * { invalidateOn: ['settings.changed'] },\n * );\n * if (summary.error !== null) {\n * return <ErrorState title=\"The summary did not load\" description={summary.error.message} />;\n * }\n * return <Button loading={summary.isLoading} onClick={summary.refetch}>Refresh</Button>;\n * }\n * ```\n */\nexport function useTapServer<N extends TapProcedureName>(\n name: N,\n input: TapProcedureInput<N>,\n options: TapQueryOptions = {},\n): TapQueryResult<TapProcedureOutput<N>> {\n const tap = useTap();\n const client = useHostQueryClient();\n const filters = useTapFilters();\n const queryKey = procedureQueryKey(\n tap.extension.installId,\n name,\n input,\n filters,\n );\n const procedure = tap.server[name];\n\n if (typeof procedure !== 'function') {\n throw new TapError(\n 'TAP_UNKNOWN_PROCEDURE',\n `Procedure \"${name}\" is not declared. Add it under server.procedures in tappify.extension.json, then run \\`tappify extension types\\`.`,\n );\n }\n\n const result = useQuery({\n queryKey,\n queryFn: () => procedure(input),\n enabled: options.enabled ?? true,\n staleTime: STALE_TIME_MS,\n retry: false,\n });\n\n useInvalidateOn(tap, client, queryKey, options.invalidateOn);\n\n const resultRefetch = result.refetch;\n const refetch = useCallback(() => {\n void resultRefetch();\n }, [resultRefetch]);\n\n return {\n data: result.data,\n error: result.error,\n isLoading: result.isLoading,\n refetch,\n };\n}\n\nfunction isSingletonHandle<T>(value: unknown): value is TapSingleton<T> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'get' in value &&\n 'set' in value &&\n 'patch' in value &&\n typeof value.get === 'function' &&\n typeof value.set === 'function' &&\n typeof value.patch === 'function'\n );\n}\n\nfunction asSingleton<T>(handle: unknown, collection: string): TapSingleton<T> {\n if (isSingletonHandle<T>(handle)) return handle;\n\n throw new TapError(\n 'TAP_UNKNOWN_COLLECTION',\n `useTapStorage(\"${collection}\") reads a singleton collection. Declare it with \"singleton\": true in tappify.extension.json, or read an id-keyed collection with tap.storage.${collection}.list().`,\n );\n}\n\n/**\n * Reads and writes the one document a singleton storage collection holds.\n *\n * @remarks\n * The argument is a collection name from the `TapStorageMap` augmentation\n * `tappify extension types` writes, and the collection has to be declared with\n * `\"singleton\": true`; an id-keyed collection throws `TAP_UNKNOWN_COLLECTION`,\n * with the `tap.storage.<name>.list()` path in the message. `data` is `undefined`\n * while the first read is in flight and `null` until the document is first\n * written. Every storage call needs the `storage:write` scope, reads included, and\n * rejects with `TAP_SCOPE_MISSING` without it. A write from another mount or\n * another browser tab of the same install refetches this one.\n *\n * @example\n * ```tsx\n * import { useTapStorage } from '@tappify/extension-sdk';\n * import { Button } from '@tappify/extension-sdk/ui';\n *\n * function CompactToggle() {\n * const preferences = useTapStorage('preferences');\n * return (\n * <Button\n * loading={preferences.isLoading}\n * onClick={() => void preferences.patch({ compact: true })}\n * >\n * Compact\n * </Button>\n * );\n * }\n * ```\n */\nexport function useTapStorage<C extends TapSingletonName>(\n collection: C,\n): TapStorageResult<TapSingletonDocument<C>> {\n type Document = TapSingletonDocument<C>;\n\n const tap = useTap();\n const client = useHostQueryClient();\n const queryKey = storageQueryKey(tap.extension.installId, collection);\n const handle = asSingleton<Document>(tap.storage[collection], collection);\n\n const result = useQuery({\n queryKey,\n queryFn: () => handle.get(),\n staleTime: STALE_TIME_MS,\n retry: false,\n });\n\n const installId = tap.extension.installId;\n const invalidate = useCallback(() => {\n void client.invalidateQueries({\n queryKey: storageQueryKey(installId, collection),\n });\n }, [client, installId, collection]);\n\n useEffect(\n () => tap.__subscribe(`storage:${collection}`, invalidate),\n [tap, collection, invalidate],\n );\n\n const save = useCallback(\n async (document: Document) => {\n await handle.set(document);\n },\n [handle],\n );\n\n const patch = useCallback(\n async (partial: Partial<Document>) => handle.patch(partial),\n [handle],\n );\n\n const resultRefetch = result.refetch;\n const refetch = useCallback(() => {\n void resultRefetch();\n }, [resultRefetch]);\n\n return {\n data: result.data,\n error: result.error,\n isLoading: result.isLoading,\n refetch,\n save,\n patch,\n };\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,aAAa,4BAA4B;AAIlD,SAAS,YAAe,KAAmB,QAA4B;AACrE,QAAM,MAAM,OAAO;AAEnB,QAAM,YAAY;AAAA,IAChB,CAAC,aAAyB,IAAI,YAAY,KAAK,QAAQ;AAAA,IACvD,CAAC,KAAK,GAAG;AAAA,EACX;AACA,QAAM,WAAW,YAAY,MAAM,OAAO,GAAG,GA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AA,IACZ,OAAO,YAA+B,OAAO,MAAM,OAAO;AAAA,IAC1D,CAAC,MAAM;AAAA,EACT;AAEA,QAAM,gBAAgB,OAAO;AAC7B,QAAM,UAAUA,aAAY,MAAM;AAChC,SAAK,cAAc;AAAA,EACrB,GAAG,CAAC,aAAa,CAAC;AAElB,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,OAAO,OAAO;AAAA,IACd,WAAW,OAAO;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["value","useCallback","useCallback"]}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TapError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QXD7WVKK.mjs";
|
|
4
4
|
|
|
5
5
|
// src/testing/environment.ts
|
|
6
6
|
var HOST_THEME = {
|
|
7
|
-
"--bg-
|
|
8
|
-
"--bg-
|
|
9
|
-
"--bg-
|
|
10
|
-
"--fg-
|
|
11
|
-
"--fg-
|
|
12
|
-
"--
|
|
13
|
-
"--
|
|
14
|
-
"--
|
|
15
|
-
"--
|
|
16
|
-
"--
|
|
17
|
-
"--
|
|
18
|
-
"--tap-space": "8px",
|
|
19
|
-
"--font-sans": "system-ui, -apple-system, sans-serif",
|
|
20
|
-
"--font-mono": "ui-monospace, SFMono-Regular, monospace",
|
|
21
|
-
"--divider": "rgba(18, 18, 18, 0.12)"
|
|
7
|
+
"--bg-paper": "#fdfdfd",
|
|
8
|
+
"--bg-canvas": "#f2f3ee",
|
|
9
|
+
"--bg-light-gray": "#edf1f5",
|
|
10
|
+
"--fg-primary": "#121212",
|
|
11
|
+
"--fg-sub": "rgba(18, 18, 18, 0.7)",
|
|
12
|
+
"--divider": "#d5d7da",
|
|
13
|
+
"--lime": "#b4d773",
|
|
14
|
+
"--deep-green": "#234e20",
|
|
15
|
+
"--danger": "#b42318",
|
|
16
|
+
"--on-accent": "#ffffff",
|
|
17
|
+
"--font-one-ui": "'Inter Variable', 'Inter', system-ui, sans-serif"
|
|
22
18
|
};
|
|
23
19
|
function installHostTheme(root) {
|
|
24
20
|
for (const [name, value] of Object.entries(HOST_THEME)) {
|
|
@@ -139,4 +135,4 @@ export {
|
|
|
139
135
|
tapMatchers,
|
|
140
136
|
registerTapMatchers
|
|
141
137
|
};
|
|
142
|
-
//# sourceMappingURL=chunk-
|
|
138
|
+
//# sourceMappingURL=chunk-SLGOHIBL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing/environment.ts","../src/testing/matchers.ts"],"sourcesContent":["const HOST_THEME: Record<string, string> = {\n '--bg-paper': '#fdfdfd',\n '--bg-canvas': '#f2f3ee',\n '--bg-light-gray': '#edf1f5',\n '--fg-primary': '#121212',\n '--fg-sub': 'rgba(18, 18, 18, 0.7)',\n '--divider': '#d5d7da',\n '--lime': '#b4d773',\n '--deep-green': '#234e20',\n '--danger': '#b42318',\n '--on-accent': '#ffffff',\n '--font-one-ui': \"'Inter Variable', 'Inter', system-ui, sans-serif\",\n};\n\n/**\n * Sets the host's eleven One UI CSS variables on an element, so a component renders in\n * a test the way it renders in the host.\n *\n * @remarks\n * Sets the light values as inline custom properties, which inherit into everything\n * below the element. The vitest and jest presets call it on\n * `document.documentElement` for you, so call it yourself only in a test that\n * renders outside `renderWithTap` or wants the variables on one subtree. It sets\n * no dark values; drive the mode through `renderWithTap`'s `theme` option, which\n * is what `useTapTheme` reads.\n *\n * @example\n * ```ts\n * import { installHostTheme } from '@tappify/extension-sdk/testing';\n *\n * function mountRoot(): HTMLElement {\n * const root = document.createElement('div');\n * installHostTheme(root);\n * document.body.append(root);\n * return root;\n * }\n * ```\n */\nexport function installHostTheme(root: HTMLElement): void {\n for (const [name, value] of Object.entries(HOST_THEME)) {\n root.style.setProperty(name, value);\n }\n}\n\nexport function clearTapPortals(root: ParentNode = document): void {\n for (const node of root.querySelectorAll('[data-tap-portal]')) node.remove();\n}\n","import { TapError } from '../client/errors';\nimport type { TapMock } from './mock';\n\n/** What each matcher returns, in the shape vitest and jest both read. */\nexport interface MatcherResult {\n pass: boolean;\n /** Built only when the runner reports, and worded for both `expect` and `not`. */\n message(): string;\n}\n\n/** The part of a runner's `expect` that `registerTapMatchers` needs. */\nexport interface MatcherTarget {\n /** Both runners take a map of matcher functions keyed by matcher name. */\n extend(matchers: Record<string, unknown>): void;\n}\n\nfunction isMock(value: unknown): value is TapMock {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'calls' in value &&\n 'documents' in value &&\n typeof value.documents === 'function'\n );\n}\n\nfunction requireMock(value: unknown, matcher: string): TapMock {\n if (isMock(value)) return value;\n throw new TapError(\n 'TAP_TEST_TARGET_INVALID',\n `${matcher}() takes the mock renderWithTap() returned. Call it as expect(mock).${matcher}(…), not on the component or the tap object.`,\n );\n}\n\nfunction tagOf(value: unknown): string {\n return Object.prototype.toString.call(value);\n}\n\nfunction sameList(left: unknown[], right: unknown[]): boolean {\n return (\n left.length === right.length &&\n left.every((item, index) => same(item, right[index]))\n );\n}\n\nfunction bytesOf(view: ArrayBufferView): number[] {\n return [...new Uint8Array(view.buffer, view.byteOffset, view.byteLength)];\n}\n\nfunction same(left: unknown, right: unknown): boolean {\n if (Object.is(left, right)) return true;\n\n const tag = tagOf(left);\n if (tag !== tagOf(right)) return false;\n\n if (\n typeof left !== 'object' ||\n typeof right !== 'object' ||\n left === null ||\n right === null\n ) {\n return false;\n }\n\n if (left instanceof Date && right instanceof Date) {\n return left.valueOf() === right.valueOf();\n }\n if (left instanceof RegExp && right instanceof RegExp) {\n return left.source === right.source && left.flags === right.flags;\n }\n if (left instanceof Map && right instanceof Map) {\n return sameList([...left.entries()], [...right.entries()]);\n }\n if (left instanceof Set && right instanceof Set) {\n return sameList([...left.values()], [...right.values()]);\n }\n if (ArrayBuffer.isView(left) && ArrayBuffer.isView(right)) {\n return sameList(bytesOf(left), bytesOf(right));\n }\n if (Array.isArray(left) && Array.isArray(right)) {\n return sameList(left, right);\n }\n if (tag !== '[object Object]') return false;\n\n const keys = Object.keys(left);\n return (\n keys.length === Object.keys(right).length &&\n keys.every(\n key =>\n key in right && same(Reflect.get(left, key), Reflect.get(right, key)),\n )\n );\n}\n\n/**\n * The four matchers that assert on what a component asked the host to do.\n *\n * @remarks\n * Each takes the mock `renderWithTap` returns, so the assertion is\n * `expect(mock).toHaveToasted(…)` rather than `expect(component)`; anything else\n * throws a `TapError` carrying `TAP_TEST_TARGET_INVALID`. A failure names every\n * call that was recorded, so a wrong path or message reads without a debugger. The\n * vitest and jest presets register these, and both declare the four on the runner's\n * own `Matchers` interface, so `expect(mock).toHaveToasted` typechecks once the\n * preset is in the setup files.\n *\n * @example\n * ```ts\n * import '@tappify/extension-sdk/testing/vitest';\n * import { createTapMock } from '@tappify/extension-sdk/testing';\n * import { expect, it } from 'vitest';\n *\n * it('toasts when a release ships', () => {\n * const mock = createTapMock();\n * mock.tap.ui.toast('A release shipped', 'neutral');\n * expect(mock).toHaveToasted('A release shipped');\n * });\n * ```\n */\nexport const tapMatchers = {\n /** Passes when `tap.nav.push` was called with exactly that path. */\n toHaveNavigatedTo(received: unknown, path: string): MatcherResult {\n const mock = requireMock(received, 'toHaveNavigatedTo');\n const pass = mock.calls.navigations.includes(path);\n return {\n pass,\n message: () =>\n pass\n ? `Expected no navigation to ${path}, but tap.nav.push was called with it.`\n : `Expected a navigation to ${path}. tap.nav.push was called with: ${\n mock.calls.navigations.length === 0\n ? 'nothing'\n : mock.calls.navigations.join(', ')\n }.`,\n };\n },\n\n /** Passes when a toast matched the string exactly, or the pattern anywhere. */\n toHaveToasted(received: unknown, expected: string | RegExp): MatcherResult {\n const mock = requireMock(received, 'toHaveToasted');\n const messages = mock.calls.toasts.map(toast => toast.message);\n const pass = messages.some(message =>\n typeof expected === 'string'\n ? message === expected\n : expected.test(message),\n );\n return {\n pass,\n message: () =>\n pass\n ? `Expected no toast matching ${String(expected)}, but one was shown.`\n : `Expected a toast matching ${String(expected)}. Toasts shown: ${\n messages.length === 0 ? 'none' : messages.join(' | ')\n }.`,\n };\n },\n\n /**\n * Passes when `tap.actions.run` was called with that action, and with input\n * deep-equal to `input` when one is given.\n */\n toHaveRunAction(\n received: unknown,\n actionId: string,\n input?: unknown,\n ): MatcherResult {\n const mock = requireMock(received, 'toHaveRunAction');\n const runs = mock.calls.actions.filter(run => run.actionId === actionId);\n const pass =\n input === undefined\n ? runs.length > 0\n : runs.some(run => same(run.input, input));\n return {\n pass,\n message: () =>\n pass\n ? `Expected tap.actions.run(\"${actionId}\") not to be called.`\n : `Expected tap.actions.run(\"${actionId}\"${\n input === undefined ? '' : `, ${JSON.stringify(input)}`\n }). Runs recorded: ${\n mock.calls.actions.length === 0\n ? 'none'\n : JSON.stringify(mock.calls.actions)\n }.`,\n };\n },\n\n /**\n * Passes when the mock's storage holds a document deep-equal to that one in\n * that collection.\n */\n toHaveStored(\n received: unknown,\n collection: string,\n document: unknown,\n ): MatcherResult {\n const mock = requireMock(received, 'toHaveStored');\n const stored = mock.documents(collection);\n const pass = stored.some(candidate => same(candidate, document));\n return {\n pass,\n message: () =>\n pass\n ? `Expected \"${collection}\" not to hold ${JSON.stringify(document)}.`\n : `Expected \"${collection}\" to hold ${JSON.stringify(document)}. It holds: ${\n stored.length === 0 ? 'nothing' : JSON.stringify(stored)\n }.`,\n };\n },\n};\n\n/**\n * Registers the four matchers on a runner's `expect`.\n *\n * @remarks\n * The vitest and jest presets call this, so a suite that loads\n * `@tappify/extension-sdk/testing/vitest` or `.../testing/jest` as a setup file\n * needs nothing else. Call it yourself only in a suite that does not use a preset,\n * and once — registering twice replaces the same four names. It adds no types of\n * its own, so a suite without a preset declares the four on the runner's `Matchers`\n * interface itself.\n *\n * @example\n * ```ts\n * import { registerTapMatchers } from '@tappify/extension-sdk/testing';\n * import { expect } from 'vitest';\n *\n * registerTapMatchers(expect);\n * ```\n */\nexport function registerTapMatchers(target: MatcherTarget): void {\n target.extend(tapMatchers);\n}\n"],"mappings":";;;;;AAAA,IAAM,aAAqC;A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