@tappify/extension-sdk 2.1.0-beta.1 → 2.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/README.md +18 -54
- package/dist/{chunk-6HETNZJY.cjs → chunk-2DBSVKAU.cjs} +1 -1
- package/dist/{chunk-6HETNZJY.cjs.map → chunk-2DBSVKAU.cjs.map} +1 -1
- package/dist/{chunk-O357OJXL.cjs → chunk-3YWVYA42.cjs} +18 -14
- package/dist/chunk-3YWVYA42.cjs.map +1 -0
- package/dist/{chunk-GAUZYBXE.cjs → chunk-5AAPD5WV.cjs} +11 -11
- package/dist/chunk-5AAPD5WV.cjs.map +1 -0
- package/dist/{chunk-SGEYDV3K.mjs → chunk-BDCX6LRQ.mjs} +3 -3
- package/dist/chunk-BDCX6LRQ.mjs.map +1 -0
- package/dist/{chunk-KZ5NGFUP.mjs → chunk-C3YNVHBP.mjs} +7 -20
- package/dist/chunk-C3YNVHBP.mjs.map +1 -0
- package/dist/{chunk-QXD7WVKK.mjs → chunk-CSTYBKZC.mjs} +1 -1
- package/dist/chunk-CSTYBKZC.mjs.map +1 -0
- package/dist/{chunk-SWG7CNTZ.mjs → chunk-CTSZ5D7S.mjs} +5 -9
- package/dist/chunk-CTSZ5D7S.mjs.map +1 -0
- package/dist/chunk-EW54H7CR.cjs +722 -0
- package/dist/chunk-EW54H7CR.cjs.map +1 -0
- package/dist/chunk-EX3NFXDK.mjs +722 -0
- package/dist/chunk-EX3NFXDK.mjs.map +1 -0
- package/dist/{chunk-A74HCO6T.cjs → chunk-G7XZSN2Q.cjs} +18 -31
- package/dist/chunk-G7XZSN2Q.cjs.map +1 -0
- package/dist/{chunk-RBIQT75L.mjs → chunk-GG3IX52W.mjs} +2 -2
- package/dist/{chunk-SLGOHIBL.mjs → chunk-IGK2AP6J.mjs} +17 -13
- package/dist/chunk-IGK2AP6J.mjs.map +1 -0
- package/dist/{chunk-VV7ELNRW.cjs → chunk-JMUK3K47.cjs} +3 -3
- package/dist/{chunk-VV7ELNRW.cjs.map → chunk-JMUK3K47.cjs.map} +1 -1
- package/dist/{chunk-SGCYEEXD.mjs → chunk-MNDVYPEP.mjs} +2 -9
- package/dist/chunk-MNDVYPEP.mjs.map +1 -0
- package/dist/{chunk-BPCGXXMD.cjs → chunk-NFUPPCX4.cjs} +18 -22
- package/dist/chunk-NFUPPCX4.cjs.map +1 -0
- package/dist/{chunk-PRCZMOLD.cjs → chunk-OPPYEA7F.cjs} +3 -3
- package/dist/{chunk-PRCZMOLD.cjs.map → chunk-OPPYEA7F.cjs.map} +1 -1
- package/dist/{chunk-7YKH4LZN.cjs → chunk-PYJMJF44.cjs} +2 -9
- package/dist/chunk-PYJMJF44.cjs.map +1 -0
- package/dist/{chunk-QA5AL3VZ.mjs → chunk-QHM7XNRK.mjs} +2 -2
- package/dist/{chunk-QA5AL3VZ.mjs.map → chunk-QHM7XNRK.mjs.map} +1 -1
- package/dist/codegen.cjs.map +1 -1
- package/dist/codegen.d.cts +7 -40
- package/dist/codegen.d.ts +7 -40
- package/dist/codegen.mjs.map +1 -1
- package/dist/{constants-BAimnqOK.d.cts → constants-DJ_KgZpN.d.cts} +8 -41
- package/dist/{constants-BAimnqOK.d.ts → constants-DJ_KgZpN.d.ts} +8 -41
- package/dist/{context-Cr93B05o.d.ts → context-Dt6xh_5t.d.cts} +4 -5
- package/dist/{context-DJ3REtdT.d.cts → context-Ml7k_V14.d.ts} +4 -5
- package/dist/{errors-Cqh0wrqt.d.ts → errors-COsBh7kd.d.cts} +2 -3
- package/dist/{errors-Cqh0wrqt.d.cts → errors-COsBh7kd.d.ts} +2 -3
- package/dist/handler-CZIlZ5vu.d.ts +227 -0
- package/dist/handler-kU9Jf36K.d.cts +227 -0
- package/dist/host.cjs +4 -4
- package/dist/host.d.cts +4 -4
- package/dist/host.d.ts +4 -4
- package/dist/host.mjs +3 -3
- package/dist/index.cjs +34 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +627 -69
- package/dist/index.d.ts +627 -69
- package/dist/index.mjs +33 -4
- package/dist/manifest.cjs +23 -132
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.d.cts +12 -93
- package/dist/manifest.d.ts +12 -93
- package/dist/manifest.mjs +9 -118
- package/dist/manifest.mjs.map +1 -1
- package/dist/server.cjs +66 -14
- 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 +61 -9
- package/dist/server.mjs.map +1 -1
- package/dist/styles.css +367 -0
- package/dist/testing/index.cjs +13 -72
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +10 -29
- package/dist/testing/index.d.ts +10 -29
- package/dist/testing/index.mjs +13 -72
- package/dist/testing/index.mjs.map +1 -1
- package/dist/testing/jest.cjs +5 -5
- package/dist/testing/jest.mjs +2 -2
- package/dist/testing/vitest.cjs +5 -5
- package/dist/testing/vitest.cjs.map +1 -1
- package/dist/testing/vitest.d.cts +0 -10
- package/dist/testing/vitest.d.ts +0 -10
- package/dist/testing/vitest.mjs +2 -2
- package/dist/testing/vitest.mjs.map +1 -1
- package/dist/{types-BYGcp5pZ.d.ts → types-DDAGLpov.d.ts} +3 -4
- package/dist/{types-I1JOZyI_.d.cts → types-DrpQSv_2.d.cts} +3 -4
- package/dist/vite-preview.cjs +125 -294
- package/dist/vite-preview.cjs.map +1 -1
- package/dist/vite-preview.d.cts +24 -6
- package/dist/vite-preview.d.ts +24 -6
- package/dist/vite-preview.mjs +118 -287
- package/dist/vite-preview.mjs.map +1 -1
- package/dist/vite.cjs +23 -133
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +7 -40
- package/dist/vite.d.ts +7 -40
- package/dist/vite.mjs +17 -127
- package/dist/vite.mjs.map +1 -1
- package/package.json +2 -12
- package/schema/extension-v2.json +121 -432
- package/dist/chunk-2CY5HVY7.mjs +0 -59
- package/dist/chunk-2CY5HVY7.mjs.map +0 -1
- package/dist/chunk-7YKH4LZN.cjs.map +0 -1
- package/dist/chunk-A74HCO6T.cjs.map +0 -1
- package/dist/chunk-BPCGXXMD.cjs.map +0 -1
- package/dist/chunk-EB5XWQAU.cjs +0 -132
- package/dist/chunk-EB5XWQAU.cjs.map +0 -1
- package/dist/chunk-GAUZYBXE.cjs.map +0 -1
- package/dist/chunk-KZ5NGFUP.mjs.map +0 -1
- package/dist/chunk-O357OJXL.cjs.map +0 -1
- package/dist/chunk-ONJMPO3P.cjs +0 -59
- package/dist/chunk-ONJMPO3P.cjs.map +0 -1
- package/dist/chunk-QJMZRV7A.mjs +0 -132
- package/dist/chunk-QJMZRV7A.mjs.map +0 -1
- package/dist/chunk-QXD7WVKK.mjs.map +0 -1
- package/dist/chunk-SGCYEEXD.mjs.map +0 -1
- package/dist/chunk-SGEYDV3K.mjs.map +0 -1
- package/dist/chunk-SLGOHIBL.mjs.map +0 -1
- package/dist/chunk-SWG7CNTZ.mjs.map +0 -1
- package/dist/client-CV1qzQgx.d.cts +0 -25
- package/dist/client-CnlSHDWE.d.ts +0 -25
- package/dist/ui/styles.css +0 -740
- package/dist/ui.cjs +0 -1018
- package/dist/ui.cjs.map +0 -1
- package/dist/ui.d.cts +0 -231
- package/dist/ui.d.ts +0 -231
- package/dist/ui.mjs +0 -1018
- package/dist/ui.mjs.map +0 -1
- package/dist/vite-preview-bootstrap.cjs +0 -66
- package/dist/vite-preview-bootstrap.cjs.map +0 -1
- package/dist/vite-preview-bootstrap.d.cts +0 -15
- package/dist/vite-preview-bootstrap.d.ts +0 -15
- package/dist/vite-preview-bootstrap.mjs +0 -66
- package/dist/vite-preview-bootstrap.mjs.map +0 -1
- package/dist/work-events-DB3WR468.d.ts +0 -547
- package/dist/work-events-Dxe7Djdy.d.cts +0 -547
- /package/dist/{chunk-RBIQT75L.mjs.map → chunk-GG3IX52W.mjs.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/codes.ts","../src/server/token.ts","../src/server/wire.ts","../src/server/handler.ts"],"sourcesContent":["import type { TapErrorCode } from '../client/errors';\n\n/**\n * The codes `createTappifyHandler` answers with itself, keyed by a short name.\n *\n * @remarks\n * Every one of these comes from the SDK, not from your own handlers: a route or\n * handler that is not there, a token that is missing or does not verify, a missing\n * event id, a body that is not JSON or is over 1 MB, a webhook Tappify rejected,\n * and the catch-all for an error a handler let escape. Throw a `TapServerError`\n * with a code of your own for anything your server decides.\n */\nexport const SERVER_ERROR_CODES = {\n ROUTE_UNKNOWN: 'TAP_ROUTE_UNKNOWN',\n HANDLER_MISSING: 'TAP_HANDLER_MISSING',\n INTERNAL_ERROR: 'TAP_INTERNAL_ERROR',\n TOKEN_MISSING: 'TAP_TOKEN_MISSING',\n TOKEN_INVALID: 'TAP_TOKEN_INVALID',\n TOKEN_AUDIENCE: 'TAP_TOKEN_AUDIENCE',\n EVENT_ID_MISSING: 'TAP_EVENT_ID_MISSING',\n BODY_INVALID: 'TAP_BODY_INVALID',\n BODY_TOO_LARGE: 'TAP_BODY_TOO_LARGE',\n WEBHOOK_REJECTED: 'TAP_WEBHOOK_REJECTED',\n} as const satisfies Record<string, TapErrorCode>;\n\n/** Every code the handler answers with itself, as a union of its own values. */\nexport type TapServerErrorCode =\n (typeof SERVER_ERROR_CODES)[keyof typeof SERVER_ERROR_CODES];\n","import {\n createLocalJWKSet,\n createRemoteJWKSet,\n jwtVerify,\n type JWTPayload,\n type JWTVerifyGetKey,\n} from 'jose';\nimport { TapError } from '../client/errors';\nimport type { TappifyClaims, VerifyTokenOptions } from './types';\n\n/**\n * The key set `verifyTappifyToken` fetches when no `jwksUrl` or `jwks` is given.\n *\n * @remarks\n * This is production. Point `jwksUrl` at the environment that is calling you when\n * you run against another one, and pass `jwks` in tests.\n */\nexport const DEFAULT_JWKS_URL =\n 'https://api.tappify.ai/api/v1/extensions/.well-known/jwks.json';\n\nconst CLOCK_TOLERANCE_SECONDS = 60;\n\nconst remoteSets = new Map<string, JWTVerifyGetKey>();\n\nfunction keySet(options: VerifyTokenOptions): JWTVerifyGetKey {\n if (options.jwks) return createLocalJWKSet(options.jwks);\n\n const url = options.jwksUrl ?? DEFAULT_JWKS_URL;\n const cached = remoteSets.get(url);\n if (cached) return cached;\n\n const created = createRemoteJWKSet(new URL(url));\n remoteSets.set(url, created);\n return created;\n}\n\nfunction readString(payload: JWTPayload, key: string): string | undefined {\n const value = payload[key];\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction toClaims(payload: JWTPayload, audience: string): TappifyClaims {\n const aud = payload.aud;\n const matches =\n aud === audience || (Array.isArray(aud) && aud.includes(audience));\n\n if (!matches) {\n throw new TapError(\n 'TAP_TOKEN_AUDIENCE',\n `This install token was issued for a different extension. Create the handler with the same extensionId as the \"id\" in tappify.extension.json, so its audience is \"${audience}\".`,\n );\n }\n\n const installId = readString(payload, 'installId');\n const extensionId = readString(payload, 'extensionId');\n const organizationId = readString(payload, 'organizationId');\n\n if (\n installId === undefined ||\n extensionId === undefined ||\n organizationId === undefined\n ) {\n throw new TapError(\n 'TAP_TOKEN_INVALID',\n `The install token is missing the installId, extensionId or organizationId claim. Verify against ${DEFAULT_JWKS_URL} and do not reuse tokens across environments.`,\n );\n }\n\n const scopes = payload.scopes;\n const userId = readString(payload, 'userId');\n\n const claims: TappifyClaims = {\n iss: readString(payload, 'iss') ?? '',\n aud: audience,\n exp: typeof payload.exp === 'number' ? payload.exp : 0,\n iat: typeof payload.iat === 'number' ? payload.iat : 0,\n installId,\n extensionId,\n projectId: readString(payload, 'projectId') ?? null,\n organizationId,\n scopes: Array.isArray(scopes)\n ? scopes.filter((scope): scope is string => typeof scope === 'string')\n : [],\n };\n\n if (userId !== undefined) claims.userId = userId;\n return claims;\n}\n\n/**\n * Verifies an install token against Tappify's signing keys and returns its\n * claims.\n *\n * @remarks\n * Checks the RS256 signature, the expiry with 60 seconds of clock tolerance, and\n * that the audience is `ext:<extensionId>`. Rejects with a `TapError` carrying\n * `TAP_TOKEN_INVALID` when the signature, the expiry or a required claim is wrong,\n * and `TAP_TOKEN_AUDIENCE` when the token was issued for another extension. A\n * remote key set is fetched once per url and cached for the process, so calling\n * this per request costs nothing after the first. `createTappifyHandler` already\n * verifies every route but health, so call this only outside the handler, or\n * where you accept a Tappify token on a route of your own.\n *\n * @example\n * ```ts\n * import { verifyTappifyToken } from '@tappify/extension-sdk/server';\n *\n * async function whoCalled(request: Request): Promise<string> {\n * const token = (request.headers.get('authorization') ?? '').replace('Bearer ', '');\n * const claims = await verifyTappifyToken(token, { extensionId: 'starter' });\n * return claims.installId;\n * }\n * ```\n */\nexport async function verifyTappifyToken(\n token: string,\n options: VerifyTokenOptions,\n): Promise<TappifyClaims> {\n const audience = `ext:${options.extensionId}`;\n\n let payload: JWTPayload;\n try {\n const verified = await jwtVerify(token, keySet(options), {\n algorithms: ['RS256'],\n clockTolerance: CLOCK_TOLERANCE_SECONDS,\n });\n payload = verified.payload;\n } catch {\n throw new TapError(\n 'TAP_TOKEN_INVALID',\n 'The install token did not verify. Check that your server reads the Authorization header unchanged, that its clock is correct, and that jwksUrl points at the Tappify environment that called you.',\n );\n }\n\n return toClaims(payload, audience);\n}\n","import type { TapServerErrorCode } from './codes';\n\nexport const INTERNAL_MESSAGE =\n 'The extension server failed to handle this call. Check your own logs; Tappify records the failure against your extension.';\n\nexport function json(data: unknown, status = 200): Response {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'content-type': 'application/json' },\n });\n}\n\nexport function wireError(\n code: string,\n message: string,\n status: number,\n): Response {\n return json({ error: { code, message } }, status);\n}\n\nexport function failure(\n code: TapServerErrorCode,\n message: string,\n status: number,\n): Response {\n return wireError(code, message, status);\n}\n\nexport function readUnknown(value: unknown, key: string): unknown {\n if (typeof value !== 'object' || value === null) return undefined;\n return (value as Record<string, unknown>)[key];\n}\n\nexport function readRecord(\n value: unknown,\n key: string,\n): Record<string, unknown> {\n const nested = readUnknown(value, key);\n return typeof nested === 'object' && nested !== null\n ? (nested as Record<string, unknown>)\n : {};\n}\n\nexport function readText(value: unknown, key: string): string | null {\n const nested = readUnknown(value, key);\n return typeof nested === 'string' ? nested : null;\n}\n","import { TapError, TapServerError } from '../client/errors';\nimport type { TapCredentialValues, TapDateRange } from '../client/types';\nimport { EVENTS } from '../manifest/constants';\nimport { SERVER_ERROR_CODES, type TapServerErrorCode } from './codes';\nimport { verifyTappifyToken } from './token';\nimport type {\n ContextBlock,\n LegacyWorkHandlers,\n MentionItems,\n MetricsInput,\n MetricsResponse,\n TappifyCallContext,\n TappifyClaims,\n TappifyDocuments,\n TappifyHandlerOptions,\n TappifyHealth,\n TappifyInstall,\n TappifyRequest,\n WorkOperation,\n} from './types';\nimport {\n INTERNAL_MESSAGE,\n failure,\n json,\n readRecord,\n readText,\n readUnknown,\n wireError,\n} from './wire';\n\n/**\n * What `createTappifyHandler` returns: a `fetch` handler, which is what Cloudflare\n * Workers, Vercel and the two adapters all take.\n */\nexport type TappifyFetchHandler = (request: Request) => Promise<Response>;\n\nconst MAX_BODY_BYTES = 1_048_576;\n\nconst WORK_OPERATIONS: readonly (WorkOperation | keyof LegacyWorkHandlers)[] = [\n 'configure',\n 'list_containers',\n 'describe_container',\n 'create',\n 'attach',\n 'comment',\n 'set_status',\n 'hydrate_event',\n 'disconnect',\n 'status',\n 'resolve',\n];\n\nconst TOKEN_FAILURES: readonly TapServerErrorCode[] = [\n SERVER_ERROR_CODES.TOKEN_INVALID,\n SERVER_ERROR_CODES.TOKEN_AUDIENCE,\n];\n\n/**\n * The token is signed by Tappify and the body is not, so the claims win wherever\n * they carry a value and the body only fills what the token leaves out.\n */\nfunction toInstall(payload: unknown, claims: TappifyClaims): TappifyInstall {\n const raw = readRecord(payload, 'install');\n return {\n id: claims.installId,\n extensionId: claims.extensionId,\n projectId: claims.projectId ?? readText(raw, 'projectId'),\n organizationId: claims.organizationId,\n };\n}\n\nfunction toPlatform(value: string | null): TappifyCallContext['platform'] {\n return value === 'ios' || value === 'android' ? value : 'all';\n}\n\nfunction toPreset(value: string | null): TapDateRange['preset'] {\n return value === '7d' || value === '30d' || value === '90d'\n ? value\n : undefined;\n}\n\nfunction toContext(payload: unknown): TappifyCallContext {\n const raw = readRecord(payload, 'context');\n const filters = readRecord(raw, 'filters');\n const rawRange = readRecord(filters, 'range');\n const from = readText(raw, 'from') ?? readText(rawRange, 'from') ?? '';\n const to = readText(raw, 'to') ?? readText(rawRange, 'to') ?? '';\n\n const range: TapDateRange = {\n from: readText(rawRange, 'from') ?? from,\n to: readText(rawRange, 'to') ?? to,\n };\n\n const preset = toPreset(readText(rawRange, 'preset'));\n if (preset !== undefined) range.preset = preset;\n\n return {\n projectId: readText(raw, 'projectId'),\n platform: toPlatform(readText(raw, 'platform')),\n from,\n to,\n filters: {\n range,\n platform: toPlatform(readText(filters, 'platform')),\n country: readText(filters, 'country') ?? 'all',\n },\n };\n}\n\nfunction toCredentials(payload: unknown): TapCredentialValues {\n const raw = readRecord(payload, 'credentials');\n const credentials: Record<string, string> = {};\n for (const [name, value] of Object.entries(raw)) {\n if (typeof value === 'string') credentials[name] = value;\n }\n return credentials;\n}\n\nfunction tooLarge(): TapServerError {\n return new TapServerError(\n SERVER_ERROR_CODES.BODY_TOO_LARGE,\n 'A Tappify request body is at most 1 MB. Return a cursor or an id the host can follow instead of inlining the payload.',\n 413,\n );\n}\n\nasync function readBody(request: Request): Promise<unknown> {\n if (request.method === 'GET' || request.method === 'HEAD') return {};\n\n const length = request.headers.get('content-length');\n if (length !== null && Number(length) > MAX_BODY_BYTES) throw tooLarge();\n\n const bytes = await request.arrayBuffer();\n if (bytes.byteLength > MAX_BODY_BYTES) throw tooLarge();\n if (bytes.byteLength === 0) return {};\n\n const text = new TextDecoder().decode(bytes);\n try {\n return JSON.parse(text);\n } catch {\n throw new TapServerError(\n SERVER_ERROR_CODES.BODY_INVALID,\n 'The request body was not JSON. Do not parse or re-encode the body before handing the Request to createTappifyHandler().',\n 400,\n );\n }\n}\n\n/**\n * The route table holds handlers whose declared input and event types the\n * manifest augmentations narrow. Method syntax keeps the parameter bivariant,\n * so a narrowed handler still fits a table the wire types as `unknown`.\n */\ntype AnyRouteHandler = {\n route(request: TappifyRequest<unknown, unknown>): unknown;\n}['route'];\n\ninterface Route {\n handler: AnyRouteHandler | undefined;\n input: unknown;\n event: unknown;\n noContent: boolean;\n}\n\nfunction route(\n handler: AnyRouteHandler | undefined,\n input: unknown,\n event?: unknown,\n noContent = false,\n): Route {\n return { handler, input, event, noContent };\n}\n\nfunction handlerFor(\n map: Partial<Record<string, AnyRouteHandler>> | undefined,\n name: string,\n): AnyRouteHandler | undefined {\n return map?.[name];\n}\n\nfunction resolveRoute(\n options: TappifyHandlerOptions,\n method: string,\n segments: string[],\n url: URL,\n payload: unknown,\n): Route | null {\n const [head, name] = segments;\n const bodyInput = readUnknown(payload, 'input') ?? {};\n\n if (head === 'metrics' && method === 'POST') {\n return route(options.metrics, bodyInput);\n }\n if (head === 'tools' && method === 'POST' && name !== undefined) {\n return route(handlerFor(options.tools, name), bodyInput);\n }\n if (head === 'mentions' && method === 'GET' && name !== undefined) {\n return route(handlerFor(options.mentions, name), {\n q: url.searchParams.get('q') ?? '',\n });\n }\n if (head === 'actions' && method === 'POST' && name !== undefined) {\n return route(handlerFor(options.actions, name), bodyInput);\n }\n if (head === 'procedures' && method === 'POST' && name !== undefined) {\n return route(handlerFor(options.procedures, name), bodyInput);\n }\n if (head === 'context' && method === 'GET' && name !== undefined) {\n return route(handlerFor(options.context, name), undefined);\n }\n if (head === 'work' && method === 'POST' && name !== undefined) {\n const operation = WORK_OPERATIONS.find(candidate => candidate === name);\n const handler =\n operation === undefined ? undefined : options.work?.[operation];\n if (operation === 'set_status' && handler === undefined) {\n const input = readRecord(payload, 'input');\n if (readText(input, 'tappifyStatus') === 'resolved') {\n // SDK v2 resolve handlers conventionally read the provider item as id.\n // eslint-disable-next-line @typescript-eslint/no-deprecated -- SDK v2 compatibility adapter.\n return route(options.work?.resolve, {\n ...input,\n id: readUnknown(input, 'externalItemId'),\n });\n }\n }\n return route(handler, bodyInput);\n }\n if (head === 'events' && method === 'POST') {\n const envelope = readRecord(payload, 'event');\n const eventName = readText(envelope, 'name');\n if (eventName === null) {\n throw new TapServerError(\n SERVER_ERROR_CODES.BODY_INVALID,\n 'The events body has no event.name. Post the envelope Tappify sends unchanged, with the event name under \"event\".',\n 400,\n );\n }\n const declared = EVENTS.find(candidate => candidate === eventName);\n return route(\n declared === undefined ? undefined : options.events?.[declared],\n undefined,\n readUnknown(envelope, 'payload') ?? {},\n true,\n );\n }\n\n return null;\n}\n\n/**\n * Builds the one `fetch` handler that answers every route Tappify calls on your\n * server.\n *\n * @remarks\n * It routes the paths under `/tappify`, minus `basePath` when your framework mounts\n * it under a prefix, and hands each matched handler a `TappifyRequest`. Every\n * route but `GET /tappify/health` needs a bearer install token, which it verifies\n * with `verifyTappifyToken`, and an `X-Tappify-Event-Id` header; a missing token is\n * 401 `TAP_TOKEN_MISSING`, a missing id 400 `TAP_EVENT_ID_MISSING`, an unknown path\n * 404 `TAP_ROUTE_UNKNOWN` and a declared name with no handler 404\n * `TAP_HANDLER_MISSING`. A body that is not JSON is 400 `TAP_BODY_INVALID` and one\n * over 1 MB is 413 `TAP_BODY_TOO_LARGE`. A `TapServerError` a handler throws is\n * answered with its own code and status, and a `TapError` other than the two token\n * failures with its own code and 400; anything else becomes 500\n * `TAP_INTERNAL_ERROR` with a fixed message, so an internal failure never reaches\n * the owner. An events route answers 204 with no body, and every other route\n * answers the handler's return value as JSON. Export the options object as well as\n * the handler: `createTestClient` takes the options.\n *\n * @example\n * ```ts\n * import {\n * createTappifyHandler,\n * type TappifyHandlerOptions,\n * } from '@tappify/extension-sdk/server';\n *\n * const handlerOptions: TappifyHandlerOptions = {\n * extensionId: 'starter',\n * health: () => ({ ok: true, version: '0.1.0' }),\n * procedures: {\n * getSummary: () => ({ installs: 1260, delta: 0.087, topKeyword: 'photo editor' }),\n * },\n * };\n *\n * const handler = createTappifyHandler(handlerOptions);\n * ```\n */\nexport function createTappifyHandler(\n options: TappifyHandlerOptions,\n): TappifyFetchHandler {\n const basePath = options.basePath ?? '';\n\n return async function handle(request: Request): Promise<Response> {\n const url = new URL(request.url);\n const path = url.pathname.startsWith(basePath)\n ? url.pathname.slice(basePath.length)\n : url.pathname;\n\n const segments = path.split('/').filter(segment => segment !== '');\n if (segments[0] !== 'tappify') {\n return failure(\n SERVER_ERROR_CODES.ROUTE_UNKNOWN,\n `Nothing is mounted at ${path}. Tappify calls paths under /tappify; set basePath if your framework mounts the handler under a prefix.`,\n 404,\n );\n }\n\n const rest = segments.slice(1);\n\n if (rest[0] === 'health' && request.method === 'GET') {\n const health: TappifyHealth = options.health\n ? await options.health()\n : { ok: true };\n return json(health);\n }\n\n const authorization = request.headers.get('authorization') ?? '';\n const token = authorization.startsWith('Bearer ')\n ? authorization.slice('Bearer '.length)\n : '';\n\n if (token === '') {\n return failure(\n SERVER_ERROR_CODES.TOKEN_MISSING,\n 'This route needs an install token. Tappify sends it as Authorization: Bearer <token>; forward the header unchanged from your framework.',\n 401,\n );\n }\n\n const eventId = request.headers.get('x-tappify-event-id');\n if (eventId === null || eventId === '') {\n return failure(\n SERVER_ERROR_CODES.EVENT_ID_MISSING,\n 'Every Tappify call carries X-Tappify-Event-Id for idempotency. Forward the header unchanged, and use it as the key when you deduplicate.',\n 400,\n );\n }\n\n try {\n const claims = await verifyTappifyToken(token, {\n extensionId: options.extensionId,\n jwksUrl: options.jwksUrl,\n jwks: options.jwks,\n });\n\n const payload = await readBody(request);\n const matched = resolveRoute(options, request.method, rest, url, payload);\n\n if (matched === null) {\n return failure(\n SERVER_ERROR_CODES.ROUTE_UNKNOWN,\n `Tappify has no ${request.method} ${path} route. The paths it calls are listed under \"Vendor server endpoints\" in the reference; check the method and the spelling.`,\n 404,\n );\n }\n\n if (matched.handler === undefined) {\n return failure(\n SERVER_ERROR_CODES.HANDLER_MISSING,\n `No handler is registered for ${request.method} ${path}. Add it to createTappifyHandler(), or remove the contribution from tappify.extension.json.`,\n 404,\n );\n }\n\n const documents = readRecord(payload, 'documents');\n\n const typed: TappifyRequest<unknown, unknown> = {\n install: toInstall(payload, claims),\n context: toContext(payload),\n input: matched.input,\n credentials: toCredentials(payload),\n documents: documents as TappifyDocuments,\n event: matched.event,\n eventId,\n claims,\n request,\n };\n\n const result = await matched.handler(typed);\n return matched.noContent\n ? new Response(null, { status: 204 })\n : json(result);\n } catch (error) {\n if (TapServerError.is(error)) {\n return wireError(error.code, error.message, error.status ?? 400);\n }\n if (TapError.is(error)) {\n const tokenFailure = TOKEN_FAILURES.find(\n candidate => candidate === error.code,\n );\n if (tokenFailure !== undefined) {\n return failure(tokenFailure, error.message, 401);\n }\n return wireError(error.code, error.message, 400);\n }\n return failure(SERVER_ERROR_CODES.INTERNAL_ERROR, INTERNAL_MESSAGE, 500);\n }\n };\n}\n\nexport type {\n ContextBlock,\n MentionItems,\n MetricsInput,\n MetricsResponse,\n TappifyClaims,\n};\n"],"mappings":";;;;;;;;;AAYO,IAAM,qBAAqB;AAAA,EAChC,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,kBAAkB;AACpB;;;ACvBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAWA,IAAM,mBACX;AAEF,IAAM,0BAA0B;AAEhC,IAAM,aAAa,oBAAI,IAA6B;AAEpD,SAAS,OAAO,SAA8C;AAC5D,MAAI,QAAQ,KAAM,QAAO,kBAAkB,QAAQ,IAAI;AAEvD,QAAM,MAAM,QAAQ,WAAW;AAC/B,QAAM,SAAS,WAAW,IAAI,GAAG;AACjC,MAAI,OAAQ,QAAO;AAEnB,QAAM,UAAU,mBAAmB,IAAI,IAAI,GAAG,CAAC;AAC/C,aAAW,IAAI,KAAK,OAAO;AAC3B,SAAO;AACT;AAEA,SAAS,WAAW,SAA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"version":3,"sources":["/home/runner/work/extension-sdk/extension-sdk/dist/chunk-O357OJXL.cjs","../src/testing/environment.ts","../src/testing/matchers.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,IAAM,WAAA,EAAqC;AAAA,EACzC,YAAA,EAAc,SAAA;AAAA,EACd,aAAA,EAAe,SAAA;AAAA,EACf,iBAAA,EAAmB,SAAA;AAAA,EACnB,cAAA,EAAgB,SAAA;AAAA,EAChB,UAAA,EAAY,uBAAA;AAAA,EACZ,WAAA,EAAa,SAAA;AAAA,EACb,QAAA,EAAU,SAAA;AAAA,EACV,cAAA,EAAgB,SAAA;AAAA,EAChB,UAAA,EAAY,SAAA;AAAA,EACZ,aAAA,EAAe,SAAA;AAAA,EACf,eAAA,EAAiB;AACnB,CAAA;AA0BO,SAAS,gBAAA,CAAiB,IAAA,EAAyB;AACxD,EAAA,IAAA,CAAA,MAAW,CAAC,IAAA,EAAM,KAAK,EAAA,GAAK,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,EAAG;AACtD,IAAA,IAAA,CAAK,KAAA,CAAM,WAAA,CAAY,IAAA,EAAM,KAAK,CAAA;AAAA,EACpC;AACF;AAEO,SAAS,eAAA,CAAgB,KAAA,EAAmB,QAAA,EAAgB;AACjE,EAAA,IAAA,CAAA,MAAW,KAAA,GAAQ,IAAA,CAAK,gBAAA,CAAiB,mBAAmB,CAAA,EAAG,IAAA,CAAK,MAAA,CAAO,CAAA;AAC7E;ADpBA;AACA;AEXA,SAAS,MAAA,CAAO,KAAA,EAAkC;AAChD,EAAA,OACE,OAAO,MAAA,IAAU,SAAA,GACjB,MAAA,IAAU,KAAA,GACV,QAAA,GAAW,MAAA,GACX,YAAA,GAAe,MAAA,GACf,OAAO,KAAA,CAAM,UAAA,IAAc,UAAA;AAE/B;AAEA,SAAS,WAAA,CAAY,KAAA,EAAgB,OAAA,EAA0B;AAC7D,EAAA,GAAA,CAAI,MAAA,CAAO,KAAK,CAAA,EAAG,OAAO,KAAA;AAC1B,EAAA,MAAM,IAAI,+BAAA;AAAA,IACR,yBAAA;AAAA,IACA,CAAA,EAAA;AACF,EAAA;AACF;AAEA;AACE,EAAA;AACF;AAEA;AACE,EAAA;AAIF;AAEA;AACE,EAAA;AACF;AAEA;AACE,EAAA;AAEA,EAAA;AACA,EAAA;AAEA,EAAA;AAME,IAAA;AACF,EAAA;AAEA,EAAA;AACE,IAAA;AACF,EAAA;AACA,EAAA;AACE,IAAA;AACF,EAAA;AACA,EAAA;AACE,IAAA;AACF,EAAA;AACA,EAAA;AACE,IAAA;AACF,EAAA;AACA,EAAA;AACE,IAAA;AACF,EAAA;AACA,EAAA;AACE,IAAA;AACF,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AAGI,IAAA;AAEF,EAAA;AAEJ;AA2Ba;AAAc;AAEzB,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AAAO,MAAA;AACL,MAAA;AASF,IAAA;AACF,EAAA;AAAA;AAGA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AAAsB,MAAA;AAItB,IAAA;AACA,IAAA;AAAO,MAAA;AACL,MAAA;AAOF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAMA,EAAA;AAKE,IAAA;AACA,IAAA;AACA,IAAA;AAIA,IAAA;AAAO,MAAA;AACL,MAAA;AAWF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAMA,EAAA;AAKE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAO,MAAA;AACL,MAAA;AAOF,IAAA;AACF,EAAA;AACF;AAqBO;AACL,EAAA;AACF;AFtGK;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/extension-sdk/extension-sdk/dist/chunk-O357OJXL.cjs","sourcesContent":[null,"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"]}
|
package/dist/chunk-ONJMPO3P.cjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _chunkGAUZYBXEcjs = require('./chunk-GAUZYBXE.cjs');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var _chunkPRCZMOLDcjs = require('./chunk-PRCZMOLD.cjs');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var _chunk6HETNZJYcjs = require('./chunk-6HETNZJY.cjs');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _chunkQ7SFCCGTcjs = require('./chunk-Q7SFCCGT.cjs');
|
|
30
|
-
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var src_exports = {};
|
|
33
|
-
_chunkQ7SFCCGTcjs.__export.call(void 0, src_exports, {
|
|
34
|
-
TAP_ERROR_CODES: () => _chunk6HETNZJYcjs.TAP_ERROR_CODES,
|
|
35
|
-
TapError: () => _chunk6HETNZJYcjs.TapError,
|
|
36
|
-
TapServerError: () => _chunk6HETNZJYcjs.TapServerError,
|
|
37
|
-
dataQueryKey: () => _chunkGAUZYBXEcjs.dataQueryKey,
|
|
38
|
-
installPrefix: () => _chunkGAUZYBXEcjs.installPrefix,
|
|
39
|
-
procedurePrefix: () => _chunkGAUZYBXEcjs.procedurePrefix,
|
|
40
|
-
procedureQueryKey: () => _chunkGAUZYBXEcjs.procedureQueryKey,
|
|
41
|
-
storageQueryKey: () => _chunkGAUZYBXEcjs.storageQueryKey,
|
|
42
|
-
useTap: () => _chunkPRCZMOLDcjs.useTap,
|
|
43
|
-
useTapAuth: () => _chunkGAUZYBXEcjs.useTapAuth,
|
|
44
|
-
useTapContext: () => _chunkGAUZYBXEcjs.useTapContext,
|
|
45
|
-
useTapFilters: () => _chunkGAUZYBXEcjs.useTapFilters,
|
|
46
|
-
useTapParams: () => _chunkGAUZYBXEcjs.useTapParams,
|
|
47
|
-
useTapProject: () => _chunkGAUZYBXEcjs.useTapProject,
|
|
48
|
-
useTapQuery: () => _chunkGAUZYBXEcjs.useTapQuery,
|
|
49
|
-
useTapServer: () => _chunkGAUZYBXEcjs.useTapServer,
|
|
50
|
-
useTapSize: () => _chunkGAUZYBXEcjs.useTapSize,
|
|
51
|
-
useTapState: () => _chunkGAUZYBXEcjs.useTapState,
|
|
52
|
-
useTapStorage: () => _chunkGAUZYBXEcjs.useTapStorage,
|
|
53
|
-
useTapTheme: () => _chunkGAUZYBXEcjs.useTapTheme
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
exports.src_exports = src_exports;
|
|
59
|
-
//# sourceMappingURL=chunk-ONJMPO3P.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/extension-sdk/extension-sdk/dist/chunk-ONJMPO3P.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;AC9BA,IAAA,YAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,WAAA,EAAA;AAAA,EAAA,eAAA,EAAA,CAAA,EAAA,GAAA,iCAAA;AAAA,EAAA,QAAA,EAAA,CAAA,EAAA,GAAA,0BAAA;AAAA,EAAA,cAAA,EAAA,CAAA,EAAA,GAAA,gCAAA;AAAA,EAAA,YAAA,EAAA,CAAA,EAAA,GAAA,8BAAA;AAAA,EAAA,aAAA,EAAA,CAAA,EAAA,GAAA,+BAAA;AAAA,EAAA,eAAA,EAAA,CAAA,EAAA,GAAA,iCAAA;AAAA,EAAA,iBAAA,EAAA,CAAA,EAAA,GAAA,mCAAA;AAAA,EAAA,eAAA,EAAA,CAAA,EAAA,GAAA,iCAAA;AAAA,EAAA,MAAA,EAAA,CAAA,EAAA,GAAA,wBAAA;AAAA,EAAA,UAAA,EAAA,CAAA,EAAA,GAAA,4BAAA;AAAA,EAAA,aAAA,EAAA,CAAA,EAAA,GAAA,+BAAA;AAAA,EAAA,aAAA,EAAA,CAAA,EAAA,GAAA,+BAAA;AAAA,EAAA,YAAA,EAAA,CAAA,EAAA,GAAA,8BAAA;AAAA,EAAA,aAAA,EAAA,CAAA,EAAA,GAAA,+BAAA;AAAA,EAAA,WAAA,EAAA,CAAA,EAAA,GAAA,6BAAA;AAAA,EAAA,YAAA,EAAA,CAAA,EAAA,GAAA,8BAAA;AAAA,EAAA,UAAA,EAAA,CAAA,EAAA,GAAA,4BAAA;AAAA,EAAA,WAAA,EAAA,CAAA,EAAA,GAAA,6BAAA;AAAA,EAAA,aAAA,EAAA,CAAA,EAAA,GAAA,+BAAA;AAAA,EAAA,WAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;ADsDA;AACA;AACE;AACF,kCAAC","file":"/home/runner/work/extension-sdk/extension-sdk/dist/chunk-ONJMPO3P.cjs","sourcesContent":[null,"/**\n * @module index\n * @mergeModuleWith <project>\n */\nexport { useTap } from './client/context';\nexport { TAP_ERROR_CODES, TapError, TapServerError } from './client/errors';\nexport type { TapErrorCode } from './client/errors';\nexport {\n useTapAuth,\n useTapContext,\n useTapFilters,\n useTapParams,\n useTapProject,\n useTapSize,\n useTapState,\n useTapTheme,\n} from './client/hooks';\nexport {\n dataQueryKey,\n installPrefix,\n procedurePrefix,\n procedureQueryKey,\n storageQueryKey,\n useTapQuery,\n useTapServer,\n useTapStorage,\n} from './client/query';\nexport type {\n TapQueryOptions,\n TapQueryResult,\n TapStorageResult,\n} from './client/query';\nexport type * from './client/types';\n"]}
|
package/dist/chunk-QJMZRV7A.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SERVER_ERROR_CODES,
|
|
3
|
-
readRecord,
|
|
4
|
-
readText,
|
|
5
|
-
readUnknown
|
|
6
|
-
} from "./chunk-KZ5NGFUP.mjs";
|
|
7
|
-
import {
|
|
8
|
-
TapServerError
|
|
9
|
-
} from "./chunk-QXD7WVKK.mjs";
|
|
10
|
-
|
|
11
|
-
// src/server/events.ts
|
|
12
|
-
var DEFAULT_BASE_URL = "https://api.tappify.ai";
|
|
13
|
-
function toHex(buffer) {
|
|
14
|
-
return Array.from(new Uint8Array(buffer)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
15
|
-
}
|
|
16
|
-
async function signWebhook(secret, body) {
|
|
17
|
-
const encoder = new TextEncoder();
|
|
18
|
-
const key = await crypto.subtle.importKey(
|
|
19
|
-
"raw",
|
|
20
|
-
encoder.encode(secret),
|
|
21
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
22
|
-
false,
|
|
23
|
-
["sign"]
|
|
24
|
-
);
|
|
25
|
-
const signature = await crypto.subtle.sign("HMAC", key, encoder.encode(body));
|
|
26
|
-
return toHex(signature);
|
|
27
|
-
}
|
|
28
|
-
async function rejectionCode(response) {
|
|
29
|
-
try {
|
|
30
|
-
const payload = await response.json();
|
|
31
|
-
return readText(readRecord(payload, "error"), "code");
|
|
32
|
-
} catch {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function sendEvent(name, payload, options) {
|
|
37
|
-
const envelope = {
|
|
38
|
-
event: name,
|
|
39
|
-
source: options.extensionId,
|
|
40
|
-
occurredAt: options.occurredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
41
|
-
dedupeKey: options.dedupeKey ?? crypto.randomUUID(),
|
|
42
|
-
payload: { ...payload }
|
|
43
|
-
};
|
|
44
|
-
if (options.build !== void 0) envelope.build = options.build;
|
|
45
|
-
const body = JSON.stringify(envelope);
|
|
46
|
-
const signature = await signWebhook(options.secret, body);
|
|
47
|
-
const url = options.endpoint ?? `${options.baseUrl ?? DEFAULT_BASE_URL}/api/v1/extensions/hooks/${options.extensionId}/${options.installId}`;
|
|
48
|
-
const send = options.fetch ?? fetch;
|
|
49
|
-
const response = await send(url, {
|
|
50
|
-
method: "POST",
|
|
51
|
-
headers: {
|
|
52
|
-
"content-type": "application/json",
|
|
53
|
-
"x-tappify-signature": signature
|
|
54
|
-
},
|
|
55
|
-
body
|
|
56
|
-
});
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
const rejection = await rejectionCode(response);
|
|
59
|
-
throw new TapServerError(
|
|
60
|
-
SERVER_ERROR_CODES.WEBHOOK_REJECTED,
|
|
61
|
-
`Tappify answered ${String(response.status)}${rejection === null ? "" : ` (${rejection})`} for ${name}. Check the inbound signing secret on the extension's Server page, and that the event is declared under contributes.webhooks.`,
|
|
62
|
-
response.status
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/server/work-events.ts
|
|
68
|
-
function nonempty(value) {
|
|
69
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
70
|
-
}
|
|
71
|
-
function validEvent(event) {
|
|
72
|
-
const type = readText(event, "type");
|
|
73
|
-
if (!["comment.created", "status.changed", "item.deleted"].includes(type ?? ""))
|
|
74
|
-
return false;
|
|
75
|
-
if (!["externalItemId", "providerEventId", "occurredAt", "dedupeKey"].every(
|
|
76
|
-
(key) => nonempty(readUnknown(event, key))
|
|
77
|
-
))
|
|
78
|
-
return false;
|
|
79
|
-
const reference = readUnknown(event, "hydrateRef");
|
|
80
|
-
const comment = readUnknown(event, "comment");
|
|
81
|
-
const status = readUnknown(event, "status");
|
|
82
|
-
if (reference !== void 0)
|
|
83
|
-
return nonempty(reference) && comment === void 0 && status === void 0;
|
|
84
|
-
if (type === "item.deleted")
|
|
85
|
-
return comment === void 0 && status === void 0;
|
|
86
|
-
if (type === "status.changed") {
|
|
87
|
-
const normalized2 = readRecord(event, "status");
|
|
88
|
-
return comment === void 0 && nonempty(normalized2.id) && nonempty(normalized2.label) && typeof normalized2.stage === "string" && ["open", "in_progress", "done"].includes(normalized2.stage);
|
|
89
|
-
}
|
|
90
|
-
const normalized = readRecord(event, "comment");
|
|
91
|
-
const author = readRecord(normalized, "author");
|
|
92
|
-
return status === void 0 && nonempty(normalized.externalCommentId) && typeof normalized.body === "string" && nonempty(normalized.createdAt) && nonempty(author.id) && nonempty(author.displayName);
|
|
93
|
-
}
|
|
94
|
-
async function sendWorkEvent(event, options) {
|
|
95
|
-
if (!validEvent(event))
|
|
96
|
-
throw new TypeError(
|
|
97
|
-
"Invalid work event: provide complete normalized content or a nonempty hydrateRef, with routing and identity fields."
|
|
98
|
-
);
|
|
99
|
-
if (!nonempty(options.callbackUrl))
|
|
100
|
-
throw new TypeError(
|
|
101
|
-
"A work event requires the callbackUrl provisioned through configure."
|
|
102
|
-
);
|
|
103
|
-
const body = JSON.stringify(event);
|
|
104
|
-
const signature = await signWebhook(options.secret, body);
|
|
105
|
-
const response = await (options.fetch ?? fetch)(options.callbackUrl, {
|
|
106
|
-
method: "POST",
|
|
107
|
-
headers: {
|
|
108
|
-
"content-type": "application/json",
|
|
109
|
-
"x-tappify-signature": signature
|
|
110
|
-
},
|
|
111
|
-
body
|
|
112
|
-
});
|
|
113
|
-
if (!response.ok) {
|
|
114
|
-
let rejection = null;
|
|
115
|
-
try {
|
|
116
|
-
rejection = readText(readRecord(await response.json(), "error"), "code");
|
|
117
|
-
} catch {
|
|
118
|
-
}
|
|
119
|
-
throw new TapServerError(
|
|
120
|
-
SERVER_ERROR_CODES.WEBHOOK_REJECTED,
|
|
121
|
-
`Tappify answered ${String(response.status)}${rejection === null ? "" : ` (${rejection})`} for work event ${event.type}. Check the callback URL and per-install work-event signing secret provisioned through configure.`,
|
|
122
|
-
response.status
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
signWebhook,
|
|
129
|
-
sendEvent,
|
|
130
|
-
sendWorkEvent
|
|
131
|
-
};
|
|
132
|
-
//# sourceMappingURL=chunk-QJMZRV7A.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/events.ts","../src/server/work-events.ts"],"sourcesContent":["import { TapServerError } from '../client/errors';\nimport type { WebhookName, WebhookPayload } from '../client/types';\nimport { SERVER_ERROR_CODES } from './codes';\nimport { readRecord, readText } from './wire';\n\n/** The body `sendEvent` posts to Tappify, and the body the signature covers. */\nexport interface WebhookEnvelope {\n /** The declared webhook name. */\n event: string;\n /** The extension id the event came from. */\n source: string;\n /** When the event happened, as an ISO timestamp. */\n occurredAt: string;\n /** The build the event belongs to, when it belongs to one. */\n build?: string;\n /** The key Tappify deduplicates on, so a retry is not counted twice. */\n dedupeKey: string;\n payload: Record<string, unknown>;\n}\n\n/** The third argument of `sendEvent`. */\nexport interface SendEventOptions {\n /** Which install the event belongs to. */\n installId: string;\n extensionId: string;\n /** The inbound signing secret from the extension's Server page. */\n secret: string;\n /** A full url to post to, which replaces `baseUrl` and the built path. */\n endpoint?: string;\n /** The Tappify origin to build the path under. Defaults to production. */\n baseUrl?: string;\n /** Defaults to a fresh UUID, so give your own to make a retry idempotent. */\n dedupeKey?: string;\n build?: string;\n /** Defaults to now, in ISO form. */\n occurredAt?: string;\n /** A `fetch` of your own, for a test or a proxy. Defaults to the global one. */\n fetch?: typeof fetch;\n}\n\nconst DEFAULT_BASE_URL = 'https://api.tappify.ai';\n\nfunction toHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map(byte => byte.toString(16).padStart(2, '0'))\n .join('');\n}\n\n/**\n * Returns the hex HMAC-SHA-256 of a raw body under a shared secret.\n *\n * @remarks\n * This is the value `sendEvent` sends as `X-Tappify-Signature`, computed over the\n * exact bytes of the body it posts. Call it directly only when you build the\n * request yourself, and sign the serialised string you send rather than\n * re-serialising the object, because a different key order is a different\n * signature. Uses Web Crypto, so it runs on Node, Cloudflare Workers and Vercel\n * alike.\n *\n * @example\n * ```ts\n * import { signWebhook } from '@tappify/extension-sdk/server';\n *\n * async function signed(body: string): Promise<Record<string, string>> {\n * return { 'x-tappify-signature': await signWebhook('whsec_test', body) };\n * }\n * ```\n */\nexport async function signWebhook(\n secret: string,\n body: string,\n): Promise<string> {\n const encoder = new TextEncoder();\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n );\n const signature = await crypto.subtle.sign('HMAC', key, encoder.encode(body));\n return toHex(signature);\n}\n\nasync function rejectionCode(response: Response): Promise<string | null> {\n try {\n const payload: unknown = await response.json();\n return readText(readRecord(payload, 'error'), 'code');\n } catch {\n return null;\n }\n}\n\n/**\n * Posts one of your declared webhook events to Tappify, signed with the install's\n * inbound secret.\n *\n * @remarks\n * The name and the payload are narrowed by the `TapWebhookMap` augmentation\n * `tappify extension types` writes. It builds the envelope, signs the serialised\n * body and posts it to the install's hook path under `baseUrl`, or to `endpoint`\n * when you give one. A response Tappify did not accept rejects with a\n * `TapServerError` whose `code` is always `TAP_WEBHOOK_REJECTED`, carrying the HTTP\n * status, and with Tappify's own code in the message text rather than in `code`;\n * the two usual causes are the wrong signing\n * secret and an event the manifest does not declare. Pass your own `dedupeKey` to\n * make a retry idempotent, because the default is a fresh UUID.\n *\n * @example\n * ```ts\n * import { sendEvent } from '@tappify/extension-sdk/server';\n *\n * async function reportAnomaly(installId: string, why: string): Promise<void> {\n * await sendEvent('anomaly.detected', { why }, {\n * installId,\n * extensionId: 'starter',\n * secret: process.env.TAPPIFY_INBOUND_SECRET ?? '',\n * dedupeKey: `anomaly-${installId}-${why}`,\n * });\n * }\n * ```\n */\nexport async function sendEvent<E extends WebhookName>(\n name: E,\n payload: WebhookPayload<E>,\n options: SendEventOptions,\n): Promise<void> {\n const envelope: WebhookEnvelope = {\n event: name,\n source: options.extensionId,\n occurredAt: options.occurredAt ?? new Date().toISOString(),\n dedupeKey: options.dedupeKey ?? crypto.randomUUID(),\n payload: { ...payload },\n };\n\n if (options.build !== undefined) envelope.build = options.build;\n\n const body = JSON.stringify(envelope);\n const signature = await signWebhook(options.secret, body);\n const url =\n options.endpoint ??\n `${options.baseUrl ?? DEFAULT_BASE_URL}/api/v1/extensions/hooks/${options.extensionId}/${options.installId}`;\n\n const send = options.fetch ?? fetch;\n const response = await send(url, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n 'x-tappify-signature': signature,\n },\n body,\n });\n\n if (!response.ok) {\n const rejection = await rejectionCode(response);\n throw new TapServerError(\n SERVER_ERROR_CODES.WEBHOOK_REJECTED,\n `Tappify answered ${String(response.status)}${rejection === null ? '' : ` (${rejection})`} for ${name}. Check the inbound signing secret on the extension's Server page, and that the event is declared under contributes.webhooks.`,\n response.status,\n );\n }\n}\n","import { TapServerError } from '../client/errors';\nimport { SERVER_ERROR_CODES } from './codes';\nimport { signWebhook } from './events';\nimport { readRecord, readText, readUnknown } from './wire';\nimport type { WorkHydratedEvent, WorkHydratedEventBase } from './work';\n\n/** An opaque provider signal to hydrate using current install credentials. */\nexport interface WorkHydrationReferenceEvent extends WorkHydratedEventBase {\n type: WorkHydratedEvent['type'];\n /** A nonempty, short-lived reference resolved by the hydrate_event handler. */\n hydrateRef: string;\n /** Normalized comment content must not accompany a reference. */\n comment?: never;\n /** Normalized status content must not accompany a reference. */\n status?: never;\n}\n\n/** Complete normalized content or an opaque reference, with stable retry identity. */\nexport type WorkEvent =\n | (WorkHydratedEvent & { hydrateRef?: never })\n | WorkHydrationReferenceEvent;\n\n/** Install-specific delivery values provisioned through work configure. */\nexport interface SendWorkEventOptions {\n /** The exact provisioned callback URL; no production default is supplied. */\n callbackUrl: string;\n /** The per-install work-event signing secret provisioned with the callback. */\n secret: string;\n /** A transport for tests or a proxy; defaults to global fetch. */\n fetch?: typeof fetch;\n}\n\nfunction nonempty(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction validEvent(event: WorkEvent): boolean {\n const type = readText(event, 'type');\n if (\n !['comment.created', 'status.changed', 'item.deleted'].includes(type ?? '')\n )\n return false;\n if (\n !['externalItemId', 'providerEventId', 'occurredAt', 'dedupeKey'].every(\n key => nonempty(readUnknown(event, key)),\n )\n )\n return false;\n\n const reference = readUnknown(event, 'hydrateRef');\n const comment = readUnknown(event, 'comment');\n const status = readUnknown(event, 'status');\n if (reference !== undefined)\n return nonempty(reference) && comment === undefined && status === undefined;\n\n if (type === 'item.deleted')\n return comment === undefined && status === undefined;\n if (type === 'status.changed') {\n const normalized = readRecord(event, 'status');\n return (\n comment === undefined &&\n nonempty(normalized.id) &&\n nonempty(normalized.label) &&\n typeof normalized.stage === 'string' &&\n ['open', 'in_progress', 'done'].includes(normalized.stage)\n );\n }\n\n const normalized = readRecord(event, 'comment');\n const author = readRecord(normalized, 'author');\n return (\n status === undefined &&\n nonempty(normalized.externalCommentId) &&\n typeof normalized.body === 'string' &&\n nonempty(normalized.createdAt) &&\n nonempty(author.id) &&\n nonempty(author.displayName)\n );\n}\n\n/**\n * Sends one provider work event to the callback provisioned for this install.\n *\n * @remarks\n * Pass the callbackUrl and secret received through configure unchanged. The\n * event's required dedupeKey identifies the logical provider signal and must be\n * reused on retries. Complete normalized content and an opaque hydrateRef are\n * mutually exclusive. The exact serialized UTF-8 body is signed with HMAC-SHA-256.\n * This callback is independent of declared alert and banner webhooks.\n */\nexport async function sendWorkEvent(\n event: WorkEvent,\n options: SendWorkEventOptions,\n): Promise<void> {\n if (!validEvent(event))\n throw new TypeError(\n 'Invalid work event: provide complete normalized content or a nonempty hydrateRef, with routing and identity fields.',\n );\n if (!nonempty(options.callbackUrl))\n throw new TypeError(\n 'A work event requires the callbackUrl provisioned through configure.',\n );\n\n const body = JSON.stringify(event);\n const signature = await signWebhook(options.secret, body);\n const response = await (options.fetch ?? fetch)(options.callbackUrl, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n 'x-tappify-signature': signature,\n },\n body,\n });\n\n if (!response.ok) {\n let rejection: string | null = null;\n try {\n rejection = readText(readRecord(await response.json(), 'error'), 'code');\n } catch {\n // Proxies may return a non-JSON rejection body.\n }\n throw new TapServerError(\n SERVER_ERROR_CODES.WEBHOOK_REJECTED,\n `Tappify answered ${String(response.status)}${rejection === null ? '' : ` (${rejection})`} for work event ${event.type}. Check the callback URL and per-install work-event signing secret provisioned through configure.`,\n response.status,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAwCA,IAAM,mBAAmB;AAEzB,SAAS,MAAM,QAA6B;AAC1C,SAAO,MAAM,KAAK,IAAI,WAAW,MA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AiB,KACrC,OAAO,WAAW,SAAS,YAC3B,SAAS,WAAW,SAAS,KAC7B,SAAS,OAAO,EAAE,KAClB,SAAS,OAAO,WAAW;AAE/B;AAYA,eAAsB,cACpB,OACA,SACe;AACf,MAAI,CAAC,WAAW,KAAK;AACnB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,MAAI,CAAC,SAAS,QAAQ,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,QAAM,OAAO,KAAK,UAAU,KAAK;AACjC,QAAM,YAAY,MAAM,YAAY,QAAQ,QAAQ,IAAI;AACxD,QAAM,WAAW,OAAO,QAAQ,SAAS,OAAO,QAAQ,aAAa;AAAA,IACnE,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,uBAAuB;AAAA,IACzB;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,QAAI,YAA2B;AAC/B,QAAI;AACF,kBAAY,SAAS,WAAW,MAAM,SAAS,KAAK,GAAG,OAAO,GAAG,MAAM;AAAA,IACzE,QAAQ;AAAA,IAER;AACA,UAAM,IAAI;AAAA,MACR,mBAAmB;AAAA,MACnB,oBAAoB,OAAO,SAAS,MAAM,CAAC,GAAG,cAAc,OAAO,KAAK,KAAK,SAAS,GAAG,mBAAmB,MAAM,IAAI;AAAA,MACtH,SAAS;AAAA,IACX;AAAA,EACF;AACF;","names":["normalized"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/errors.ts"],"sourcesContent":["/** Every code a `TapError` the SDK raises carries. */\nexport type TapErrorCode =\n | 'TAP_OUTSIDE_HOST'\n | 'TAP_SCOPE_MISSING'\n | 'TAP_UNKNOWN_COLLECTION'\n | 'TAP_UNKNOWN_PROCEDURE'\n | 'TAP_NO_PORTAL'\n | 'TAP_NO_QUERY_CLIENT'\n | 'TAP_MANIFEST_INVALID'\n | 'TAP_ENTRY_MISSING'\n | 'TAP_STYLES_UNRESOLVED'\n | 'TAP_SCHEMA_UNRESOLVED'\n | 'TAP_TOKEN_MISSING'\n | 'TAP_TOKEN_INVALID'\n | 'TAP_TOKEN_AUDIENCE'\n | 'TAP_EVENT_ID_MISSING'\n | 'TAP_BODY_INVALID'\n | 'TAP_BODY_TOO_LARGE'\n | 'TAP_ROUTE_UNKNOWN'\n | 'TAP_HANDLER_MISSING'\n | 'TAP_INTERNAL_ERROR'\n | 'TAP_WEBHOOK_REJECTED'\n | 'TAP_TEST_TARGET_INVALID';\n\n/**\n * The same codes as `TapErrorCode`, as an array to iterate or check membership\n * against at runtime.\n */\nexport const TAP_ERROR_CODES: readonly TapErrorCode[] = [\n 'TAP_OUTSIDE_HOST',\n 'TAP_SCOPE_MISSING',\n 'TAP_UNKNOWN_COLLECTION',\n 'TAP_UNKNOWN_PROCEDURE',\n 'TAP_NO_PORTAL',\n 'TAP_NO_QUERY_CLIENT',\n 'TAP_MANIFEST_INVALID',\n 'TAP_ENTRY_MISSING',\n 'TAP_STYLES_UNRESOLVED',\n 'TAP_SCHEMA_UNRESOLVED',\n 'TAP_TOKEN_MISSING',\n 'TAP_TOKEN_INVALID',\n 'TAP_TOKEN_AUDIENCE',\n 'TAP_EVENT_ID_MISSING',\n 'TAP_BODY_INVALID',\n 'TAP_BODY_TOO_LARGE',\n 'TAP_ROUTE_UNKNOWN',\n 'TAP_HANDLER_MISSING',\n 'TAP_INTERNAL_ERROR',\n 'TAP_WEBHOOK_REJECTED',\n 'TAP_TEST_TARGET_INVALID',\n];\n\nconst CODE_SET = new Set<string>(TAP_ERROR_CODES);\n\n/**\n * The error the SDK and the host raise when a call cannot be served at all.\n *\n * @remarks\n * The SDK throws it for a mount outside the host (`TAP_OUTSIDE_HOST`), a\n * collection or procedure the manifest does not declare\n * (`TAP_UNKNOWN_COLLECTION`, `TAP_UNKNOWN_PROCEDURE`), a missing portal or query\n * client, a token the server rejected, and a misused testing helper. The host\n * turns a refused read or write into `TAP_SCOPE_MISSING`. Branch on `code`, which\n * is stable; the message is prose and changes. An error your own server raised is\n * a `TapServerError` instead.\n *\n * @example\n * ```tsx\n * import { TapError, useTapQuery } from '@tappify/extension-sdk';\n * import { ErrorState } from '@tappify/extension-sdk/ui';\n *\n * function Revenue() {\n * const revenue = useTapQuery({\n * kind: 'revenue',\n * range: { from: '2026-09-01', to: '2026-09-08' },\n * });\n * if (TapError.is(revenue.error) && revenue.error.code === 'TAP_SCOPE_MISSING') {\n * return <ErrorState title=\"Revenue is not shared with this extension\" />;\n * }\n * return <span>{revenue.data?.mrr ?? 0}</span>;\n * }\n * ```\n */\nexport class TapError extends Error {\n readonly code: TapErrorCode;\n\n constructor(code: TapErrorCode, message: string) {\n super(message);\n this.name = 'TapError';\n this.code = code;\n }\n\n /**\n * Narrows an unknown value to a `TapError`, by name and by a code it\n * recognises, so it holds across module instances.\n */\n static is(value: unknown): value is TapError {\n return (\n value instanceof Error &&\n value.name === 'TapError' &&\n 'code' in value &&\n typeof value.code === 'string' &&\n CODE_SET.has(value.code)\n );\n }\n}\n\n/**\n * The error a vendor server throws to answer a Tappify call with a code and a\n * message the owner sees.\n *\n * @remarks\n * `createTappifyHandler` catches it and answers `{ error: { code, message } }`\n * with `status`, or 400 when no status was given; the host relays both to the\n * calling mount, where they arrive as the `error` of `useTapServer`. Pick a code\n * of your own and keep it stable — the SDK's own codes are `SERVER_ERROR_CODES` —\n * and write the message for the owner, who reads it on screen.\n *\n * @example\n * ```ts\n * import { TapServerError } from '@tappify/extension-sdk/server';\n *\n * function assertRange(days: number) {\n * if (days > 0) return;\n * throw new TapServerError(\n * 'RANGE_TOO_SHORT',\n * 'getSummary needs a range of at least one day. Widen the date picker, then retry.',\n * 400,\n * );\n * }\n * ```\n */\nexport class TapServerError extends Error {\n readonly code: string;\n readonly status: number | undefined;\n\n constructor(code: string, message: string, status?: number) {\n super(message);\n this.name = 'TapServerError';\n this.code = code;\n this.status = status;\n }\n\n /** The wire body the handler answers with, without the status. */\n toJSON(): { error: { code: string; message: string } } {\n return { error: { code: this.code, message: this.message } };\n }\n\n /**\n * Narrows an unknown value to a `TapServerError` by name and by carrying a\n * string `code`, so it holds across module instances.\n */\n static is(value: unknown): value is TapServerError {\n return (\n value instanceof Error &&\n value.name === 'TapServerError' &&\n 'code' in value &&\n typeof value.code === 'string'\n );\n }\n}\n"],"mappings":";AA4BO,IAAM,kBAA2C;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,WAAW,IAAI,IAAY,eAAe;AA+BzC,IAAM,WAAN,cAAuB,MAAM;AAAA,EAGlC,YAAY,MAAoB,SAAiB;AAC/C,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,GAAG,OAAmC;AAC3C,WACE,iBAAiB,SACjB,MAAM,SAAS,cACf,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,SAAS,IAAI,MAAM,IAAI;AAAA,EAE3B;AACF;AA2BO,IAAM,iBAAN,cAA6B,MAAM;AAAA,EAIxC,YAAY,MAAc,SAAiB,QAAiB;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA,EAGA,SAAuD;AACrD,WAAO,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,SAAS,KAAK,QAAQ,EAAE;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,GAAG,OAAyC;AACjD,WACE,iBAAiB,SACjB,MAAM,SAAS,oBACf,UAAU,SACV,OAAO,MAAM,SAAS;AAAA,EAE1B;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/manifest/constants.ts"],"sourcesContent":["import type { ToolDeclaration } from './types';\n\nexport const SCOPES = [\n {\n key: 'ui:render',\n label: 'Render UI',\n description:\n 'Render the declared pages, tabs, widgets, row actions and settings panel, and open chat with a visible prompt',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'projects:read',\n label: 'Read the project',\n description: 'Project name, platforms and store identity',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'analytics:read',\n label: 'Read analytics',\n description: 'Downloads, impressions, page views and conversion series',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'store.metadata:read',\n label: 'Read store metadata',\n description: 'Listing metadata, keyword set and keyword positions',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'reviews:read',\n label: 'Read store reviews',\n description: 'Review text, ratings and replies',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'review.threads:read',\n label: 'Read Review threads',\n description:\n 'Review threads, comments, screenshot descriptors, build context and safe device context',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'crashes:read',\n label: 'Read crash data',\n description: 'Crash-free rate and issue counts',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'revenue:read',\n label: 'Read revenue',\n description: 'MRR, revenue series and refund counts',\n requiresSecurityReview: false,\n requiresJustification: true,\n },\n {\n key: 'metrics:write',\n label: 'Write connector metrics',\n description:\n 'Write the metrics this extension declares into the metrics store',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'alerts:write',\n label: 'Raise alerts and banners',\n description:\n 'Turn declared webhooks into alerts and banners, at most three a day per project',\n requiresSecurityReview: false,\n requiresJustification: true,\n },\n {\n key: 'insights:write',\n label: 'Post insights',\n description: 'Post insights to Home and to chat',\n requiresSecurityReview: false,\n requiresJustification: true,\n },\n {\n key: 'ai:tools',\n label: 'Add assistant tools',\n description: 'Offer tools and mentions to the assistant',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'ai:actions',\n label: 'Run assistant actions',\n description: 'Run declared actions, each behind the approval card',\n requiresSecurityReview: true,\n requiresJustification: true,\n },\n {\n key: 'store.metadata:write',\n label: 'Propose store metadata changes',\n description: 'Propose listing changes through a Tappify approval',\n requiresSecurityReview: true,\n requiresJustification: true,\n },\n {\n key: 'autopilot:trigger',\n label: 'Trigger automated store actions',\n description: 'Start automated store actions on the owner’s behalf',\n requiresSecurityReview: true,\n requiresJustification: true,\n },\n {\n key: 'work:create',\n label: 'Create work items',\n description: 'Create issues, pages or messages in the vendor’s system',\n requiresSecurityReview: false,\n requiresJustification: true,\n },\n {\n key: 'work:sync',\n label: 'Sync work items',\n description: 'Sync comments and status on created work items',\n requiresSecurityReview: false,\n requiresJustification: true,\n },\n {\n key: 'storage:write',\n label: 'Use hosted storage',\n description:\n 'Read and write this extension’s own hosted storage collections',\n requiresSecurityReview: false,\n requiresJustification: false,\n },\n {\n key: 'messaging:send',\n label: 'Send messages to end users',\n description:\n 'Send messages or push notifications to the owner’s end users through owner-supplied credentials',\n requiresSecurityReview: true,\n requiresJustification: true,\n },\n {\n key: 'ai:skills',\n label: 'Shape the assistant',\n description:\n 'Add skills, prompt templates and context providers that shape the assistant’s behaviour',\n requiresSecurityReview: false,\n requiresJustification: true,\n },\n] as const;\n\nexport type ScopeDefinition = (typeof SCOPES)[number];\n/** Every scope an extension can ask for under `scopes` in its manifest. */\nexport type ScopeKey = ScopeDefinition['key'];\n\nexport const SCOPE_KEYS: readonly ScopeKey[] = SCOPES.map(scope => scope.key);\n\nexport const SLOTS = [\n 'kpi-row',\n 'insights',\n 'sidebar',\n 'below-chart',\n 'below-list',\n] as const;\n/** The anchors on a host page a widget can be declared at. */\nexport type SlotId = (typeof SLOTS)[number];\n\nexport const CHARTS = [\n 'installs-activity',\n 'conversion',\n 'release-cadence',\n] as const;\nexport type HostChart = (typeof CHARTS)[number];\n\nexport const PAGES = [\n {\n key: 'overview',\n label: 'Home',\n route: '/projects/:id/overview',\n slots: ['kpi-row', 'insights', 'sidebar'],\n charts: ['installs-activity'],\n tabs: true,\n banners: true,\n },\n {\n key: 'analytics',\n label: 'Analytics',\n route: '/projects/:id/analytics',\n slots: ['kpi-row', 'below-chart', 'sidebar'],\n charts: ['installs-activity', 'conversion'],\n tabs: true,\n banners: true,\n },\n {\n key: 'deployments',\n label: 'Deployments',\n route: '/projects/:id/deployments',\n slots: ['sidebar', 'below-list'],\n charts: ['release-cadence'],\n tabs: true,\n banners: false,\n },\n {\n key: 'ai_chat',\n label: 'Assistant',\n route: 'chat',\n slots: [],\n charts: [],\n tabs: false,\n banners: false,\n },\n] as const;\n\nexport type PageDefinition = (typeof PAGES)[number];\n/** The host pages a contribution can attach a tab, widget or banner to. */\nexport type HostPage = PageDefinition['key'];\n\nexport const PAGE_KEYS: readonly HostPage[] = PAGES.map(page => page.key);\n\nexport const TABLES = [\n { key: 'analytics.keywords', label: 'Keywords' },\n { key: 'analytics.reviews', label: 'Reviews' },\n { key: 'deployments.releases', label: 'Releases' },\n { key: 'deployments.builds', label: 'Builds' },\n] as const;\n\nexport type TableDefinition = (typeof TABLES)[number];\nexport type HostTable = TableDefinition['key'];\n\nexport const TABLE_KEYS: readonly HostTable[] = TABLES.map(table => table.key);\n\nexport const KINDS = [\n 'page',\n 'tab',\n 'widget',\n 'series',\n 'banner',\n 'rowAction',\n 'marker',\n 'settings',\n 'storage',\n 'connector',\n 'webhook',\n 'tool',\n 'mention',\n 'action',\n 'knowledge',\n 'skill',\n 'prompt',\n 'context',\n 'work',\n] as const;\nexport type ContributionKind = (typeof KINDS)[number];\n\nexport const CATEGORIES = [\n 'market_data',\n 'subscriptions',\n 'product_analytics',\n 'crashes',\n 'attribution',\n 'experiments',\n 'messaging',\n 'session_replay',\n 'localization',\n 'design',\n 'ci_cd',\n 'trackers',\n 'support',\n 'chat',\n 'ad_monetization',\n 'warehouse',\n 'compliance',\n 'additional_stores',\n] as const;\nexport type ExtensionCategory = (typeof CATEGORIES)[number];\n\nexport const EVENTS = [\n 'release.shipped',\n 'metadata.changed',\n 'keyword.set_changed',\n 'screenshots.updated',\n 'price.changed',\n 'featuring.started',\n 'score.changed',\n 'incident.opened',\n 'incident.resolved',\n 'playbook.step_approved',\n 'review.thread_opened',\n 'review.thread_resolved',\n 'approval.requested',\n 'digest.sent',\n 'install.created',\n 'install.paused',\n 'install.resumed',\n 'install.revoked',\n 'install.token_rotated',\n 'scopes.changed',\n 'settings.changed',\n] as const;\n/** Every event Tappify emits, which a mount or a server can subscribe to. */\nexport type HostEventName = (typeof EVENTS)[number];\n\nexport const SERVED_SDK_MAJORS: readonly number[] = [2];\n\n/** The `kind` of every read `tap.data.query` accepts, one per scope it needs. */\nexport type DataQueryKind =\n | 'project'\n | 'series'\n | 'keywords'\n | 'listing'\n | 'reviews'\n | 'crashes'\n | 'revenue';\n\nexport const QUERY_SCOPES: Record<DataQueryKind, ScopeKey> = {\n project: 'projects:read',\n series: 'analytics:read',\n keywords: 'store.metadata:read',\n listing: 'store.metadata:read',\n reviews: 'reviews:read',\n crashes: 'crashes:read',\n revenue: 'revenue:read',\n};\n\n/**\n * The keys a tool's answer carries for each `returns` kind it may declare.\n * `validateToolResponse`, `tappify extension doctor` and the host all read\n * this one table, so a wrong body fails the same way wherever it is checked.\n */\nexport const CARD_KEYS: Record<ToolDeclaration['returns'], string[]> = {\n value: ['label', 'value'],\n series: ['label', 'points'],\n table: ['columns', 'rows'],\n list: ['items'],\n comparison: ['label', 'left', 'right'],\n};\n\nexport const findScope = (key: string): ScopeDefinition | undefined =>\n SCOPES.find(scope => scope.key === key);\n\nexport const findPage = (key: string): PageDefinition | undefined =>\n PAGES.find(page => page.key === key);\n\nexport const findTable = (key: string): TableDefinition | undefined =>\n TABLES.find(table => table.key === key);\n\nexport const slotsForPage = (page: string): readonly SlotId[] =>\n findPage(page)?.slots ?? [];\n"],"mappings":";AAEO,IAAM,SAAS;A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cesContent":["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,GAAG,CAAC,KAAK,MAAM,CAAC;AAE7D,SAAO,qBAAqB,WAAW,UAAU,QAAQ;AAC3D;AAEA,IAAM,aAAa,CAAC,QAA0B,IAAI;AAClD,IAAM,gBAAgB,CAAC,QAA6B,IAAI;AACxD,IAAM,gBAAgB,CAAC,QAAyB,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AC;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 +0,0 @@
|
|
|
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;AAAA,EACzC,cAAc;AAAA,EACd,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,aAAa;AAAA,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