@mrrocket/sdk 0.26.0 → 0.28.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/CHANGELOG.md CHANGED
@@ -2,7 +2,29 @@
2
2
 
3
3
  All notable changes to this package. It follows semantic versioning; before 1.0 a minor version may change an API.
4
4
 
5
- ## 0.26.0 (not published yet; MRRocket's `/api/sdk/preview` must be live first)
5
+ ## 0.28.0
6
+
7
+ The messenger shows when the team's AI agent is writing. Web and script tag; React Native is unchanged.
8
+
9
+ - **Typing dots:** while MRRocket's agent writes an answer in the chat on screen, three soft dots stand where its answer will come (announced as "Typing…"). They show right after the visitor sends, so the chat is never silent for the seconds the answer takes, and they go when the answer arrives or the agent stops. It needs MRRocket's side of this release (`conversation.typing` in the chat); against an older MRRocket nothing shows, as before.
10
+ - While the agent writes, the chat on screen is read every 1.5 s instead of every 4 s, so its answer appears as soon as it is there.
11
+ - New word for translations: "Typing…".
12
+ - Version reported in event batches: `0.28.0`.
13
+
14
+ ## 0.27.0
15
+
16
+ The messenger's Help tab and its articles, on the web and with the script tag. React Native is unchanged. Tables need MRRocket's side of this release (it answers `blocks=table`); against an older MRRocket an article reads as before.
17
+
18
+ - **The bar says where you are:** inside a collection it names the collection beside the back arrow, and over an article the collection the article is in, instead of "Help" over a second heading. Help's first view has no heading under the bar any more; only a search's results carry a small "Search results" line.
19
+ - **One search field:** the same field in the same place in every view of Help. It no longer gets thinner when the list under it is longer than the panel (it shrank to about a third of its height on a long collection). Home's "Ask a question" field and "New conversation" keep their height the same way.
20
+ - **One list for collections and articles:** cards like Home's conversations, 8px apart, with the name in bold, at most two gray lines under it and the arrow in the middle. A collection shows three of its articles' names and how many it holds. The rounded lines that showed between rows are gone.
21
+ - **Tables in articles:** a new block `{ type: "table", head, rows }` (`ArticleBlock`), drawn as a table with a head row that scrolls sideways inside the article when it is wider than the panel. `article(id, signal, "table")` asks MRRocket for it (`blocks=table`); a widget that does not ask, this package's older versions and the React Native messenger, keeps getting each row as a line of a list ("Free · Pro · Max"), as before.
22
+ - **Articles read calmly:** the text at 15px with more room between lines and parts, clear `h2` and `h3`, lists indented with room between their items, links in the accent color with a soft underline, inline code on a gray chip, quotes, code blocks and rules with their own room. The title stands once: a text that opens with the title as its heading starts under it, and the collection moved from above the title into the bar.
23
+ - Opening a collection no longer puts the cursor into the search field (Help's first view still does). A collection that is gone while a visitor is inside it shows the collections again instead of an empty list.
24
+ - The word "Most read articles" is no longer used; MRRocket keeps sending its translation, so older versions stay whole.
25
+ - Version reported in event batches: `0.27.0`.
26
+
27
+ ## 0.26.0
6
28
 
7
29
  - **Preview mode (web, script tag and Next.js):** with `?mrr_preview=<token>` in the address the SDK reads the change that waits for approval in MRRocket (new page copy, one version of a test, a rewritten page) from `GET /api/sdk/preview` and shows it on the real page like a shipped winner: published texts, the test's version forced as `ck_preview` would, and for pages that mark nothing a short list of changes (`set` one element's words, `body` the page's text, `meta` title and description). MRRocket's request view uses it for its before and after pictures. The token is signed by MRRocket, short-lived and bound to one request and product.
8
30
  - **The page says when it is ready:** `<html data-mrr-preview="loading">` at once, `"ready"` when the change is on the page, `"failed"` when it could not be read. What found no place (a text the page does not mark, a selector that is not there, an element that reads something else) is listed in `data-mrr-preview-missed`, never dropped. Beside the attributes one unseen status line (`<div role="status" data-mrr-preview-status>`, a transparent pixel) reads `mrr-preview-ready` and what was missed, for a browser that can only wait for text.
@@ -12,7 +34,7 @@ All notable changes to this package. It follows semantic versioning; before 1.0
12
34
  - **Script tag:** the preview and the edit bar are a file of their own, `sdk-preview.js` (`mrrocket-preview.js` in the package), loaded only with `mrr_preview` in the address; `sdk.js` grows by the token check alone.
13
35
  - Version reported in event batches: `0.26.0`.
14
36
 
15
- ## 0.25.0 (not published yet)
37
+ ## 0.25.0
16
38
 
17
39
  - **Tests your server decides:** `trackVariant(key, { config, distinctId })` in `@mrrocket/sdk/next/server` returns the version like `getVariant` and records `$exposure {experiment, variant}` for that person with the server key (`MRROCKET_SERVER_KEY` or `serverKey`), so a checkout, a price or an email your server chooses is counted like a page test. It sends nothing while the test is not running or its winner is kept for everyone, for an unknown person, for a version a preview forces, or without the server key (one console warning), and waits at most 2.5 s (`timeoutMs`). Pairs with MRRocket's new test type "In your code".
18
40
  - Version reported in event batches: `0.25.0`.
@@ -28,7 +50,7 @@ All notable changes to this package. It follows semantic versioning; before 1.0
28
50
  - **Overlapping tests:** when two running tests change the same text, the first in the config wins and is the only one recorded; a development build warns once with both keys. `overlaps(config)` lists them.
29
51
  - Version reported in event batches: `0.24.0`.
30
52
 
31
- ## 0.23.1 (not published yet)
53
+ ## 0.23.1
32
54
 
33
55
  - **Withdrawing consent now reaches MRRocket from the React provider.** In 0.23.0 `$consent_off` waited in the queue, and the provider's consent effect emptied the queue before anything was sent, so it never went out. It now goes at once, by beacon or `fetch` with `keepalive`, signed with `userHash`, and arrives even if the page closes right after. Everything else in the queue is still dropped. Nothing goes out for an anonymous visitor, a page that starts with consent off, or a browser's privacy signal. The script tag and React Native sent it correctly already.
34
56
  - Version reported in event batches: `0.23.1`.
package/README.md CHANGED
@@ -525,7 +525,7 @@ A running test needs a stable id on the server (the `ck_id` cookie with `consent
525
525
 
526
526
  ## 18. Messenger (0.9.0)
527
527
 
528
- A chat bubble like Featurebase's or Intercom's messenger, with three tabs: **Home** (greeting, "Ask a question", the open conversations, top articles), **Messages** (the chats with your team) and **Help** (your published help articles from Support › Help center, searchable, read in the panel). Every chat is a Support conversation (channel "Chat") in MRRocket's inbox: you answer there, or the Customer experience agent does (Support › Automation › AI answers). A new answer while the panel is closed plays a short sound, shows a count on the bubble and a preview card above it.
528
+ A chat bubble like Featurebase's or Intercom's messenger, with three tabs: **Home** (greeting, "Ask a question", the open conversations, top articles), **Messages** (the chats with your team) and **Help** (your published help articles from Support › Help center by collection, searchable, read in the panel with headings, lists, links, code and, from 0.27.0, tables that scroll sideways inside the article). Every chat is a Support conversation (channel "Chat") in MRRocket's inbox: you answer there, or the Customer experience agent does (Support › Automation › AI answers). A new answer while the panel is closed plays a short sound, shows a count on the bubble and a preview card above it.
529
529
 
530
530
  ```tsx
531
531
  import { Messenger, useMessenger } from "@mrrocket/sdk/next";
@@ -110,6 +110,8 @@ export interface ChatMessage {
110
110
  from: "visitor" | "team" | "ai" | "auto";
111
111
  body: string;
112
112
  at: string;
113
+ /** A team reply's sender, by first name (servers from 2026-11-19 on): "Lukas · Team". */
114
+ name?: string;
113
115
  /** Help articles an answer drew on (servers from SDK 0.9 on). */
114
116
  articles?: {
115
117
  id: string;
@@ -146,6 +148,15 @@ export type ArticleBlock = {
146
148
  text: string;
147
149
  } | {
148
150
  type: "hr";
151
+ }
152
+ /**
153
+ * A table (0.27.0): `head` is its first row when it has one (else empty), every row has the same number of cells.
154
+ * Sent only to a widget that asks for it (`article(id, signal, "table")`); every other one gets the rows as a list.
155
+ */
156
+ | {
157
+ type: "table";
158
+ head: ArticleSpan[][];
159
+ rows: ArticleSpan[][][];
149
160
  };
150
161
  export interface Article {
151
162
  id: string;
@@ -222,10 +233,12 @@ export interface ChatSummary {
222
233
  }
223
234
  /** One chat (the one asked for, else the visitor's newest, open or closed) and its messages. */
224
235
  export interface ChatThread {
236
+ /** `typing`: the team's AI agent is writing an answer in it right now (server 2026-11-27; older servers leave it out). */
225
237
  conversation: {
226
238
  id: string;
227
239
  status: "open" | "solved";
228
240
  seenAt?: string;
241
+ typing?: boolean;
229
242
  } | null;
230
243
  messages: ChatMessage[];
231
244
  /** All the visitor's conversations, the latest activity first (0.19). */
@@ -323,7 +336,11 @@ export declare const createApi: (c: Conn) => {
323
336
  articles: (q?: string, signal?: AbortSignal) => Promise<{
324
337
  articles: ArticleSummary[];
325
338
  }>;
326
- article: (id: string, signal?: AbortSignal) => Promise<Article>;
339
+ /**
340
+ * One article as blocks. `blocks` names the newer kinds of block this widget draws ("table", 0.27.0): MRRocket
341
+ * sends those only when asked, so a widget that draws none (older versions, the apps) keeps getting lines of text.
342
+ */
343
+ article: (id: string, signal?: AbortSignal, blocks?: string) => Promise<Article>;
327
344
  messengerLook: (signal?: AbortSignal) => Promise<MessengerLook>;
328
345
  rateArticle: (id: string, helpful: boolean) => Promise<{
329
346
  counted: boolean;
@@ -117,7 +117,11 @@ var createApi = (c) => {
117
117
  /** Where a sent file of this visitor's chat is read (an image's src, a PDF's link). */
118
118
  attachmentUrl: (id) => `${base}/messages/attachments/${encodeURIComponent(id)}?${qs(me, "")}`,
119
119
  articles: (q, signal) => call(`${base}/articles?${qs({ key: c.apiKey, q })}`, void 0, signal),
120
- article: (id, signal) => call(`${base}/articles/${encodeURIComponent(id)}?${qs(me)}`, void 0, signal),
120
+ /**
121
+ * One article as blocks. `blocks` names the newer kinds of block this widget draws ("table", 0.27.0): MRRocket
122
+ * sends those only when asked, so a widget that draws none (older versions, the apps) keeps getting lines of text.
123
+ */
124
+ article: (id, signal, blocks) => call(`${base}/articles/${encodeURIComponent(id)}?${qs({ ...me, blocks })}`, void 0, signal),
121
125
  messengerLook: (signal) => call(`${base}/messenger?${qs({ key: c.apiKey })}`, void 0, signal),
122
126
  rateArticle: (id, helpful) => post(`/articles/${encodeURIComponent(id)}/rate`, { helpful })
123
127
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/api-client.ts"],"sourcesContent":["/**\n * The SDK's fetch client and the shapes it reads, without React, so the script tag's widgets (src/script) use it too.\n * `./api` re-exports all of it with the `useApi` hook.\n */\nimport { warnUnsigned } from \"./identity\";\nimport { currentLocale, t } from \"./i18n\";\n\nexport type PostStatus = \"review\" | \"planned\" | \"progress\" | \"shipped\";\n\n/** Read at the moment it is shown, so it follows the visitor's language. */\nexport const STATUS_LABEL: Record<PostStatus, string> = {\n get review() {\n return t(\"Under review\");\n },\n get planned() {\n return t(\"Planned\");\n },\n get progress() {\n return t(\"In progress\");\n },\n get shipped() {\n return t(\"Shipped\");\n },\n};\n\nexport interface FeedbackBoardInfo {\n id: string;\n label: string;\n}\n\nexport interface FeedbackPost {\n id: string;\n title: string;\n body: string;\n board: string;\n status: PostStatus;\n votes: number;\n comments: number;\n voted: boolean;\n createdAt: string;\n /** \"Lena K.\", \"Anonymous\" or \"Team\". Missing from servers before SDK 0.6. */\n author?: string;\n}\n\n/** The product's public face for the board's header. */\nexport interface FeedbackProduct {\n name: string;\n logo: string | null;\n /** The domain's favicon, tried when `logo` does not load. Older servers leave it out. */\n logoFallback?: string | null;\n}\n\nexport interface FeedbackList {\n boards: FeedbackBoardInfo[];\n posts: FeedbackPost[];\n product?: FeedbackProduct;\n}\n\nexport interface FeedbackRoadmap {\n /** `review` (Backlog) comes from servers of SDK 0.6 on. */\n columns: { review?: FeedbackPost[]; planned: FeedbackPost[]; progress: FeedbackPost[]; shipped: FeedbackPost[] };\n}\n\nexport interface ChangelogEntry {\n id: string;\n title: string;\n body: string;\n publishedAt: string;\n}\n\nexport interface FeedbackComment {\n id: string;\n body: string;\n author: string;\n isTeam: boolean;\n postedAt: string;\n}\n\nexport type SurveyQuestionKind = \"nps\" | \"rating\" | \"single\" | \"multi\" | \"text\";\n\nexport interface SurveyQuestion {\n key: string;\n kind: SurveyQuestionKind;\n title: string;\n description?: string;\n required: boolean;\n options?: string[];\n /**\n * 0.21.0: what each option says in the visitor's language, parallel to `options`. An answer is still recorded as the\n * `options` value, so rules and numbers do not split by language.\n */\n labels?: string[];\n scale?: number;\n low?: string;\n high?: string;\n placeholder?: string;\n}\n\nexport interface SurveyDefinition {\n id: string;\n name: string;\n type: string;\n thanks: string;\n questions: SurveyQuestion[];\n}\n\nexport type SurveyAnswer = number | string | string[];\n\n/** A file in the messenger's chat: a screenshot, a photo or a PDF the visitor sent (servers from SDK 0.15 on). */\nexport interface ChatFile {\n /** From an upload: the signed id a message sends. In a message: the file's own id (`attachmentUrl` reads it). */\n id: string;\n name: string;\n type: \"image/png\" | \"image/jpeg\" | \"image/webp\" | \"image/gif\" | \"application/pdf\";\n /** Bytes. */\n size: number;\n}\n\n/** What the messenger can send: pictures and PDFs, at most 10 MB each, 4 per message. */\nexport const CHAT_FILE_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\", \"application/pdf\"] as const;\nexport const CHAT_FILE_MAX_BYTES = 10 * 1024 * 1024;\nexport const CHAT_FILES_PER_MESSAGE = 4;\n\n/** A file to upload: a Blob or File on the web, the image picker's `{ uri, name, type }` in React Native. */\nexport type ChatUpload = Blob | { uri: string; name: string; type: string };\n\n/** The bug context a visitor message carries; the server fills browser and system from the user agent when left out. */\nexport interface ChatContext {\n browser?: string;\n os?: string;\n /** \"1440×900\". */\n viewport?: string;\n}\n\n/** One message of the messenger's chat. \"visitor\" is the person on the site; the rest come from the product's team. */\nexport interface ChatMessage {\n id: string;\n from: \"visitor\" | \"team\" | \"ai\" | \"auto\";\n body: string;\n at: string;\n /** Help articles an answer drew on (servers from SDK 0.9 on). */\n articles?: { id: string; title: string }[];\n /** Files sent with it (servers from SDK 0.15 on). */\n attachments?: ChatFile[];\n}\n\n/** A published help article in a list (the messenger's Help tab). */\nexport interface ArticleSummary {\n id: string;\n title: string;\n collection: string;\n excerpt: string;\n updatedAt: string;\n}\n\n/** A run of text inside an article block. Links are http(s), mailto or tel only. */\nexport interface ArticleSpan {\n text: string;\n href?: string;\n bold?: boolean;\n italic?: boolean;\n code?: boolean;\n}\n\n/** An article's content as blocks, written with textContent (never parsed as HTML). */\nexport type ArticleBlock =\n | { type: \"h2\" | \"h3\" | \"p\" | \"quote\"; spans: ArticleSpan[] }\n | { type: \"ul\" | \"ol\"; items: ArticleSpan[][] }\n | { type: \"code\"; text: string }\n | { type: \"hr\" };\n\nexport interface Article {\n id: string;\n title: string;\n collection: string;\n updatedAt: string;\n blocks: ArticleBlock[];\n}\n\n/** Where the chat button sits: a corner, the middle of the top or bottom edge, or the middle of a side. */\nexport type MessengerPosition = \"top-left\" | \"top-center\" | \"top-right\" | \"middle-left\" | \"middle-right\" | \"bottom-left\" | \"bottom-center\" | \"bottom-right\";\n\n/** How round the messenger is. */\nexport type MessengerCorners = \"round\" | \"soft\" | \"square\";\n\n/** The radii per corner style, in px: the panel or sheet, message bubbles (and their tail), cards, fields and buttons. */\nexport const CORNERS: Record<MessengerCorners, { panel: number; bubble: number; tail: number; card: number; field: number }> = {\n round: { panel: 22, bubble: 18, tail: 6, card: 16, field: 20 },\n soft: { panel: 14, bubble: 12, tail: 4, card: 10, field: 10 },\n square: { panel: 6, bubble: 6, tail: 2, card: 4, field: 4 },\n};\n\n/** The messenger's look and texts as set in MRRocket › Support › Messenger (servers from SDK 0.9 on). */\nexport interface MessengerLook {\n accent: string;\n /** Up to two more colors blended into Home's background glow (MRRocket from 0.16; older servers leave it out). */\n glow?: string[];\n theme: \"light\" | \"dark\" | \"auto\";\n position: MessengerPosition;\n title: string;\n greeting: string;\n label: string;\n /** How soon the team usually answers (MRRocket from 0.10; older servers leave it out). */\n replyTime?: \"minutes\" | \"hours\" | \"day\";\n /** A round chat button in the app (React Native) too. */\n appLauncher?: boolean;\n help: boolean;\n /** The Updates tab with the published changelog (MRRocket from 0.22; older servers leave it out). */\n updates?: boolean;\n sound: boolean;\n preview: boolean;\n askEmail: boolean;\n /** How round panel, bubbles, cards and fields are (MRRocket from 0.15; older servers leave it out: round). */\n corners?: MessengerCorners;\n /** The site's own font (the default) or the system's (web only; from 0.15). */\n font?: \"site\" | \"system\";\n /** Home's top: plain like the rest, or in the accent color (from 0.15; older servers leave it out: plain). */\n header?: \"plain\" | \"color\";\n /** \"Powered by MRRocket\" at the bottom; the server sends false only on plans that may hide it (from 0.15). */\n branding?: boolean;\n /** The logo at the top left of Home: the one uploaded in MRRocket, else the product's favicon; without it the title's first letter. */\n logo?: string;\n /** The product's favicon, the round mark in the chat's head (from 0.17; without it the title's first letter). */\n icon?: string;\n /** The AI agent's name on its answers (from 0.17; empty or left out: \"AI agent\"). */\n agentName?: string;\n /** The AI agent's picture beside its answers (from 0.17). */\n agentPhoto?: string;\n}\n\n/** The link behind \"Powered by MRRocket\". */\nexport const BRAND_URL = \"https://mrrocket.dev/?utm_source=messenger&utm_medium=powered-by\";\n\n/** The line under \"Send us a message\" and in the chat's head. */\nexport const replyLine = (time: MessengerLook[\"replyTime\"]) =>\n time === \"minutes\" ? t(\"We usually reply in a few minutes\") : time === \"day\" ? t(\"We usually reply within a day\") : t(\"We usually reply in a few hours\");\n\n/** Black or white, whichever reads better on the accent (a light custom color gets dark text). */\nexport const inkOn = (hex: string) => {\n const m = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);\n if (!m) return \"#ffffff\";\n const [r, g, b] = [m[1], m[2], m[3]].map((x) => {\n const c = parseInt(x, 16) / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.45 ? \"#111214\" : \"#ffffff\";\n};\n\n/** One of the visitor's conversations in their list (0.19). */\nexport interface ChatSummary {\n id: string;\n status: \"open\" | \"solved\";\n /** The visitor's first words. */\n subject: string;\n /** The newest message, its body cut to a preview. */\n last: ChatMessage | null;\n /** Up to when the visitor read it, on any device (servers from 0.24.0). */\n seenAt?: string;\n}\n\n/** One chat (the one asked for, else the visitor's newest, open or closed) and its messages. */\nexport interface ChatThread {\n conversation: { id: string; status: \"open\" | \"solved\"; seenAt?: string } | null;\n messages: ChatMessage[];\n /** All the visitor's conversations, the latest activity first (0.19). */\n conversations?: ChatSummary[];\n /** The visitor gave an email already: the messenger stops asking. */\n hasEmail: boolean;\n}\n\n/**\n * For the count and the preview of unread answers, after a read: an answer the team took back and a conversation it\n * archived leave them. Of a conversation that is not on screen the list brings only the newest message, so an answer\n * newer than that one is gone.\n */\nexport const stillThere = (t: ChatThread, chats: ChatSummary[]) => (m: { id: string; at: string; chat: string }) => {\n if (m.chat === t.conversation?.id) return t.messages.some((x) => x.id === m.id);\n const last = chats.find((c) => c.id === m.chat)?.last;\n return !!last && m.at <= last.at;\n};\n\nexport class ApiError extends Error {\n status: number;\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n}\n\ninterface Conn {\n host: string;\n apiKey: string;\n distinctId: string;\n user?: { id?: string; [key: string]: unknown };\n /**\n * The identity hash of `distinctId` (0.16.0, see identity.ts), sent with every request that names the visitor: a\n * JSON field next to `distinctId`, a query parameter, a form field. Leave it out for any other id.\n */\n userHash?: string;\n}\n\n// Not URLSearchParams: React Native's lacks `set` in older versions, and the apps use this client too.\n// `lang` goes along so the answer's words can be in the visitor's language; \"\" leaves it out.\nconst qs = (params: Record<string, string | undefined>, lang = currentLocale()) =>\n Object.entries({ ...params, lang })\n .filter((e): e is [string, string] => !!e[1])\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n\n/** A POST's address: its body names the visitor, the query only the language of the words in its answer. */\nconst withLang = (url: string) => {\n const q = qs({});\n return q ? `${url}?${q}` : url;\n};\n\nconst call = async <T>(url: string, init: RequestInit | undefined, signal?: AbortSignal): Promise<T> => {\n let res: Response;\n try {\n res = await fetch(url, {\n ...init,\n signal,\n // A form (a file upload) sets its own multipart type with the boundary.\n headers: typeof init?.body === \"string\" ? { \"content-type\": \"application/json\" } : undefined,\n });\n } catch (e) {\n if ((e as Error).name === \"AbortError\") throw e;\n throw new ApiError(t(\"Could not reach the server. Check your connection and try again.\"), 0);\n }\n if (!res.ok) {\n // A missing or wrong identity hash: the console says once how to sign the user id.\n warnUnsigned(res.status);\n let detail = \"\";\n try {\n detail = ((await res.json()) as { error?: string }).error ?? \"\";\n } catch {\n // Not JSON; the status is enough.\n }\n throw new ApiError(detail || (res.status === 429 ? t(\"Too many requests. Try again in a minute.\") : t(\"Something went wrong. Please try again.\")), res.status);\n }\n return (await res.json()) as T;\n};\n\n/** The small fetch client behind the widgets. Every read takes an AbortSignal so unmounting cancels it. */\nexport const createApi = (c: Conn) => {\n const base = `${c.host}/api/sdk`;\n const who = { key: c.apiKey, distinctId: c.distinctId, user: c.user, userHash: c.userHash };\n // Every query that names the visitor names its hash too.\n const me = { key: c.apiKey, distinctId: c.distinctId, userHash: c.userHash };\n const post = <T>(path: string, body: Record<string, unknown>, signal?: AbortSignal) =>\n call<T>(withLang(`${base}${path}`), { method: \"POST\", body: JSON.stringify({ ...who, ...body }) }, signal);\n return {\n list: (o: { board?: string; sort?: \"top\" | \"new\"; q?: string }, signal?: AbortSignal) =>\n call<FeedbackList>(`${base}/feedback?${qs({ ...me, board: o.board, sort: o.sort, q: o.q })}`, undefined, signal),\n post: (id: string, signal?: AbortSignal) =>\n call<FeedbackPost>(`${base}/feedback/${encodeURIComponent(id)}?${qs(me)}`, undefined, signal),\n roadmap: (signal?: AbortSignal) => call<FeedbackRoadmap>(`${base}/feedback/roadmap?${qs(me)}`, undefined, signal),\n changelog: (signal?: AbortSignal) => call<{ entries: ChangelogEntry[] }>(`${base}/feedback/changelog?${qs({ key: c.apiKey })}`, undefined, signal),\n submit: (p: { title: string; body?: string; board: string }) => post<FeedbackPost>(\"/feedback\", p),\n vote: (id: string) => post<{ voted: boolean; votes: number }>(`/feedback/${encodeURIComponent(id)}/vote`, {}),\n comments: (id: string, signal?: AbortSignal) =>\n call<{ comments: FeedbackComment[] }>(`${base}/feedback/${encodeURIComponent(id)}/comments?${qs({ key: c.apiKey })}`, undefined, signal),\n comment: (id: string, body: string) => post<FeedbackComment>(`/feedback/${encodeURIComponent(id)}/comments`, { body }),\n survey: (url: string, signal?: AbortSignal) =>\n call<{ survey: SurveyDefinition | null }>(`${base}/surveys?${qs({ ...me, url })}`, undefined, signal),\n seen: (id: string) => post<unknown>(`/surveys/${encodeURIComponent(id)}/seen`, { user: undefined }),\n respond: (id: string, r: { answers: Record<string, SurveyAnswer>; completed: boolean; seconds: number }) =>\n post<unknown>(`/surveys/${encodeURIComponent(id)}/respond`, r),\n /**\n * One chat by id, else the visitor's newest; `conversations` lists them all. `aiLabel`: the messenger says \"AI agent\"\n * beside an answer's name, so the answer comes without its AI notice line (from 0.22.0).\n */\n chat: (signal?: AbortSignal, conversation?: string) => call<ChatThread>(`${base}/messages?${qs({ ...me, conversation, aiLabel: \"1\" })}`, undefined, signal),\n /**\n * A message; `attachments` are upload ids from `uploadChatFile` (then the body may be empty). `conversation` is\n * the chat it answers, or \"new\" to start one; without it, the running chat or else a new one.\n */\n sendChat: (m: { body: string; conversation?: string; email?: string; url?: string; attachments?: string[]; context?: ChatContext }) => post<ChatThread>(\"/messages\", { ...m, aiLabel: true }),\n /** The visitor read a chat up to `at` (the newest message they saw): MRRocket counts it read on every device and shows \"Seen\" to the team (0.24.0). */\n seenChat: (conversation: string, at: string) => post<{ seenAt: string | null }>(\"/messages/seen\", { conversation, at, user: undefined }),\n /** Uploads one picked file for the next message (pictures and PDFs, at most 10 MB); answers its upload id. */\n uploadChatFile: (file: ChatUpload, signal?: AbortSignal) => {\n const form = new FormData();\n form.append(\"key\", c.apiKey);\n form.append(\"distinctId\", c.distinctId);\n if (c.userHash) form.append(\"userHash\", c.userHash);\n if (\"uri\" in file) form.append(\"file\", file as unknown as Blob);\n else form.append(\"file\", file, (file as Blob & { name?: string }).name || \"file\");\n return call<ChatFile>(withLang(`${base}/messages/attachments`), { method: \"POST\", body: form }, signal);\n },\n /** Where a sent file of this visitor's chat is read (an image's src, a PDF's link). */\n attachmentUrl: (id: string) => `${base}/messages/attachments/${encodeURIComponent(id)}?${qs(me, \"\")}`,\n articles: (q?: string, signal?: AbortSignal) => call<{ articles: ArticleSummary[] }>(`${base}/articles?${qs({ key: c.apiKey, q })}`, undefined, signal),\n article: (id: string, signal?: AbortSignal) =>\n call<Article>(`${base}/articles/${encodeURIComponent(id)}?${qs(me)}`, undefined, signal),\n messengerLook: (signal?: AbortSignal) => call<MessengerLook>(`${base}/messenger?${qs({ key: c.apiKey })}`, undefined, signal),\n rateArticle: (id: string, helpful: boolean) => post<{ counted: boolean }>(`/articles/${encodeURIComponent(id)}/rate`, { helpful }),\n };\n};\n\nexport type Api = ReturnType<typeof createApi>;\n"],"mappings":";AAIA,SAAS,oBAAoB;AAC7B,SAAS,eAAe,SAAS;AAK1B,IAA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QAAQ,MAAO,KAAkC,QAAQ,MAAM;AAChF,aAAO,KAAe,SAAS,GAAG,IAAI,uBAAuB,GAAG,EAAE,QAAQ,QAAQ,MAAM,KAAK,GAAG,MAAM;AAAA,IAC1G;AAAA;AAAA,IAEA,eAAe,CAAC,OAAe,GAAG,IAAI,yBAAyB,mBAAmB,EAAE,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC;AAAA,IACnG,UAAU,CAAC,GAAY,WAAyB,KAAqC,GAAG,IAAI,aAAa,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,QAAW,MAAM;AAAA,IACtJ,SAAS,CAAC,IAAY,WAClB,KAAc,GAAG,IAAI,aAAa,mBAAmB,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,QAAW,MAAM;AAAA,IAC3F,eAAe,CAAC,WAAyB,KAAoB,GAAG,IAAI,cAAc,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,QAAW,MAAM;AAAA,IAC5H,aAAa,CAAC,IAAY,YAAqB,KAA2B,aAAa,mBAAmB,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;AAAA,EACrI;AACJ;","names":["t"]}
1
+ {"version":3,"sources":["../src/api-client.ts"],"sourcesContent":["/**\n * The SDK's fetch client and the shapes it reads, without React, so the script tag's widgets (src/script) use it too.\n * `./api` re-exports all of it with the `useApi` hook.\n */\nimport { warnUnsigned } from \"./identity\";\nimport { currentLocale, t } from \"./i18n\";\n\nexport type PostStatus = \"review\" | \"planned\" | \"progress\" | \"shipped\";\n\n/** Read at the moment it is shown, so it follows the visitor's language. */\nexport const STATUS_LABEL: Record<PostStatus, string> = {\n get review() {\n return t(\"Under review\");\n },\n get planned() {\n return t(\"Planned\");\n },\n get progress() {\n return t(\"In progress\");\n },\n get shipped() {\n return t(\"Shipped\");\n },\n};\n\nexport interface FeedbackBoardInfo {\n id: string;\n label: string;\n}\n\nexport interface FeedbackPost {\n id: string;\n title: string;\n body: string;\n board: string;\n status: PostStatus;\n votes: number;\n comments: number;\n voted: boolean;\n createdAt: string;\n /** \"Lena K.\", \"Anonymous\" or \"Team\". Missing from servers before SDK 0.6. */\n author?: string;\n}\n\n/** The product's public face for the board's header. */\nexport interface FeedbackProduct {\n name: string;\n logo: string | null;\n /** The domain's favicon, tried when `logo` does not load. Older servers leave it out. */\n logoFallback?: string | null;\n}\n\nexport interface FeedbackList {\n boards: FeedbackBoardInfo[];\n posts: FeedbackPost[];\n product?: FeedbackProduct;\n}\n\nexport interface FeedbackRoadmap {\n /** `review` (Backlog) comes from servers of SDK 0.6 on. */\n columns: { review?: FeedbackPost[]; planned: FeedbackPost[]; progress: FeedbackPost[]; shipped: FeedbackPost[] };\n}\n\nexport interface ChangelogEntry {\n id: string;\n title: string;\n body: string;\n publishedAt: string;\n}\n\nexport interface FeedbackComment {\n id: string;\n body: string;\n author: string;\n isTeam: boolean;\n postedAt: string;\n}\n\nexport type SurveyQuestionKind = \"nps\" | \"rating\" | \"single\" | \"multi\" | \"text\";\n\nexport interface SurveyQuestion {\n key: string;\n kind: SurveyQuestionKind;\n title: string;\n description?: string;\n required: boolean;\n options?: string[];\n /**\n * 0.21.0: what each option says in the visitor's language, parallel to `options`. An answer is still recorded as the\n * `options` value, so rules and numbers do not split by language.\n */\n labels?: string[];\n scale?: number;\n low?: string;\n high?: string;\n placeholder?: string;\n}\n\nexport interface SurveyDefinition {\n id: string;\n name: string;\n type: string;\n thanks: string;\n questions: SurveyQuestion[];\n}\n\nexport type SurveyAnswer = number | string | string[];\n\n/** A file in the messenger's chat: a screenshot, a photo or a PDF the visitor sent (servers from SDK 0.15 on). */\nexport interface ChatFile {\n /** From an upload: the signed id a message sends. In a message: the file's own id (`attachmentUrl` reads it). */\n id: string;\n name: string;\n type: \"image/png\" | \"image/jpeg\" | \"image/webp\" | \"image/gif\" | \"application/pdf\";\n /** Bytes. */\n size: number;\n}\n\n/** What the messenger can send: pictures and PDFs, at most 10 MB each, 4 per message. */\nexport const CHAT_FILE_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\", \"application/pdf\"] as const;\nexport const CHAT_FILE_MAX_BYTES = 10 * 1024 * 1024;\nexport const CHAT_FILES_PER_MESSAGE = 4;\n\n/** A file to upload: a Blob or File on the web, the image picker's `{ uri, name, type }` in React Native. */\nexport type ChatUpload = Blob | { uri: string; name: string; type: string };\n\n/** The bug context a visitor message carries; the server fills browser and system from the user agent when left out. */\nexport interface ChatContext {\n browser?: string;\n os?: string;\n /** \"1440×900\". */\n viewport?: string;\n}\n\n/** One message of the messenger's chat. \"visitor\" is the person on the site; the rest come from the product's team. */\nexport interface ChatMessage {\n id: string;\n from: \"visitor\" | \"team\" | \"ai\" | \"auto\";\n body: string;\n at: string;\n /** A team reply's sender, by first name (servers from 2026-11-19 on): \"Lukas · Team\". */\n name?: string;\n /** Help articles an answer drew on (servers from SDK 0.9 on). */\n articles?: { id: string; title: string }[];\n /** Files sent with it (servers from SDK 0.15 on). */\n attachments?: ChatFile[];\n}\n\n/** A published help article in a list (the messenger's Help tab). */\nexport interface ArticleSummary {\n id: string;\n title: string;\n collection: string;\n excerpt: string;\n updatedAt: string;\n}\n\n/** A run of text inside an article block. Links are http(s), mailto or tel only. */\nexport interface ArticleSpan {\n text: string;\n href?: string;\n bold?: boolean;\n italic?: boolean;\n code?: boolean;\n}\n\n/** An article's content as blocks, written with textContent (never parsed as HTML). */\nexport type ArticleBlock =\n | { type: \"h2\" | \"h3\" | \"p\" | \"quote\"; spans: ArticleSpan[] }\n | { type: \"ul\" | \"ol\"; items: ArticleSpan[][] }\n | { type: \"code\"; text: string }\n | { type: \"hr\" }\n /**\n * A table (0.27.0): `head` is its first row when it has one (else empty), every row has the same number of cells.\n * Sent only to a widget that asks for it (`article(id, signal, \"table\")`); every other one gets the rows as a list.\n */\n | { type: \"table\"; head: ArticleSpan[][]; rows: ArticleSpan[][][] };\n\nexport interface Article {\n id: string;\n title: string;\n collection: string;\n updatedAt: string;\n blocks: ArticleBlock[];\n}\n\n/** Where the chat button sits: a corner, the middle of the top or bottom edge, or the middle of a side. */\nexport type MessengerPosition = \"top-left\" | \"top-center\" | \"top-right\" | \"middle-left\" | \"middle-right\" | \"bottom-left\" | \"bottom-center\" | \"bottom-right\";\n\n/** How round the messenger is. */\nexport type MessengerCorners = \"round\" | \"soft\" | \"square\";\n\n/** The radii per corner style, in px: the panel or sheet, message bubbles (and their tail), cards, fields and buttons. */\nexport const CORNERS: Record<MessengerCorners, { panel: number; bubble: number; tail: number; card: number; field: number }> = {\n round: { panel: 22, bubble: 18, tail: 6, card: 16, field: 20 },\n soft: { panel: 14, bubble: 12, tail: 4, card: 10, field: 10 },\n square: { panel: 6, bubble: 6, tail: 2, card: 4, field: 4 },\n};\n\n/** The messenger's look and texts as set in MRRocket › Support › Messenger (servers from SDK 0.9 on). */\nexport interface MessengerLook {\n accent: string;\n /** Up to two more colors blended into Home's background glow (MRRocket from 0.16; older servers leave it out). */\n glow?: string[];\n theme: \"light\" | \"dark\" | \"auto\";\n position: MessengerPosition;\n title: string;\n greeting: string;\n label: string;\n /** How soon the team usually answers (MRRocket from 0.10; older servers leave it out). */\n replyTime?: \"minutes\" | \"hours\" | \"day\";\n /** A round chat button in the app (React Native) too. */\n appLauncher?: boolean;\n help: boolean;\n /** The Updates tab with the published changelog (MRRocket from 0.22; older servers leave it out). */\n updates?: boolean;\n sound: boolean;\n preview: boolean;\n askEmail: boolean;\n /** How round panel, bubbles, cards and fields are (MRRocket from 0.15; older servers leave it out: round). */\n corners?: MessengerCorners;\n /** The site's own font (the default) or the system's (web only; from 0.15). */\n font?: \"site\" | \"system\";\n /** Home's top: plain like the rest, or in the accent color (from 0.15; older servers leave it out: plain). */\n header?: \"plain\" | \"color\";\n /** \"Powered by MRRocket\" at the bottom; the server sends false only on plans that may hide it (from 0.15). */\n branding?: boolean;\n /** The logo at the top left of Home: the one uploaded in MRRocket, else the product's favicon; without it the title's first letter. */\n logo?: string;\n /** The product's favicon, the round mark in the chat's head (from 0.17; without it the title's first letter). */\n icon?: string;\n /** The AI agent's name on its answers (from 0.17; empty or left out: \"AI agent\"). */\n agentName?: string;\n /** The AI agent's picture beside its answers (from 0.17). */\n agentPhoto?: string;\n}\n\n/** The link behind \"Powered by MRRocket\". */\nexport const BRAND_URL = \"https://mrrocket.dev/?utm_source=messenger&utm_medium=powered-by\";\n\n/** The line under \"Send us a message\" and in the chat's head. */\nexport const replyLine = (time: MessengerLook[\"replyTime\"]) =>\n time === \"minutes\" ? t(\"We usually reply in a few minutes\") : time === \"day\" ? t(\"We usually reply within a day\") : t(\"We usually reply in a few hours\");\n\n/** Black or white, whichever reads better on the accent (a light custom color gets dark text). */\nexport const inkOn = (hex: string) => {\n const m = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);\n if (!m) return \"#ffffff\";\n const [r, g, b] = [m[1], m[2], m[3]].map((x) => {\n const c = parseInt(x, 16) / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.45 ? \"#111214\" : \"#ffffff\";\n};\n\n/** One of the visitor's conversations in their list (0.19). */\nexport interface ChatSummary {\n id: string;\n status: \"open\" | \"solved\";\n /** The visitor's first words. */\n subject: string;\n /** The newest message, its body cut to a preview. */\n last: ChatMessage | null;\n /** Up to when the visitor read it, on any device (servers from 0.24.0). */\n seenAt?: string;\n}\n\n/** One chat (the one asked for, else the visitor's newest, open or closed) and its messages. */\nexport interface ChatThread {\n /** `typing`: the team's AI agent is writing an answer in it right now (server 2026-11-27; older servers leave it out). */\n conversation: { id: string; status: \"open\" | \"solved\"; seenAt?: string; typing?: boolean } | null;\n messages: ChatMessage[];\n /** All the visitor's conversations, the latest activity first (0.19). */\n conversations?: ChatSummary[];\n /** The visitor gave an email already: the messenger stops asking. */\n hasEmail: boolean;\n}\n\n/**\n * For the count and the preview of unread answers, after a read: an answer the team took back and a conversation it\n * archived leave them. Of a conversation that is not on screen the list brings only the newest message, so an answer\n * newer than that one is gone.\n */\nexport const stillThere = (t: ChatThread, chats: ChatSummary[]) => (m: { id: string; at: string; chat: string }) => {\n if (m.chat === t.conversation?.id) return t.messages.some((x) => x.id === m.id);\n const last = chats.find((c) => c.id === m.chat)?.last;\n return !!last && m.at <= last.at;\n};\n\nexport class ApiError extends Error {\n status: number;\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n}\n\ninterface Conn {\n host: string;\n apiKey: string;\n distinctId: string;\n user?: { id?: string; [key: string]: unknown };\n /**\n * The identity hash of `distinctId` (0.16.0, see identity.ts), sent with every request that names the visitor: a\n * JSON field next to `distinctId`, a query parameter, a form field. Leave it out for any other id.\n */\n userHash?: string;\n}\n\n// Not URLSearchParams: React Native's lacks `set` in older versions, and the apps use this client too.\n// `lang` goes along so the answer's words can be in the visitor's language; \"\" leaves it out.\nconst qs = (params: Record<string, string | undefined>, lang = currentLocale()) =>\n Object.entries({ ...params, lang })\n .filter((e): e is [string, string] => !!e[1])\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n\n/** A POST's address: its body names the visitor, the query only the language of the words in its answer. */\nconst withLang = (url: string) => {\n const q = qs({});\n return q ? `${url}?${q}` : url;\n};\n\nconst call = async <T>(url: string, init: RequestInit | undefined, signal?: AbortSignal): Promise<T> => {\n let res: Response;\n try {\n res = await fetch(url, {\n ...init,\n signal,\n // A form (a file upload) sets its own multipart type with the boundary.\n headers: typeof init?.body === \"string\" ? { \"content-type\": \"application/json\" } : undefined,\n });\n } catch (e) {\n if ((e as Error).name === \"AbortError\") throw e;\n throw new ApiError(t(\"Could not reach the server. Check your connection and try again.\"), 0);\n }\n if (!res.ok) {\n // A missing or wrong identity hash: the console says once how to sign the user id.\n warnUnsigned(res.status);\n let detail = \"\";\n try {\n detail = ((await res.json()) as { error?: string }).error ?? \"\";\n } catch {\n // Not JSON; the status is enough.\n }\n throw new ApiError(detail || (res.status === 429 ? t(\"Too many requests. Try again in a minute.\") : t(\"Something went wrong. Please try again.\")), res.status);\n }\n return (await res.json()) as T;\n};\n\n/** The small fetch client behind the widgets. Every read takes an AbortSignal so unmounting cancels it. */\nexport const createApi = (c: Conn) => {\n const base = `${c.host}/api/sdk`;\n const who = { key: c.apiKey, distinctId: c.distinctId, user: c.user, userHash: c.userHash };\n // Every query that names the visitor names its hash too.\n const me = { key: c.apiKey, distinctId: c.distinctId, userHash: c.userHash };\n const post = <T>(path: string, body: Record<string, unknown>, signal?: AbortSignal) =>\n call<T>(withLang(`${base}${path}`), { method: \"POST\", body: JSON.stringify({ ...who, ...body }) }, signal);\n return {\n list: (o: { board?: string; sort?: \"top\" | \"new\"; q?: string }, signal?: AbortSignal) =>\n call<FeedbackList>(`${base}/feedback?${qs({ ...me, board: o.board, sort: o.sort, q: o.q })}`, undefined, signal),\n post: (id: string, signal?: AbortSignal) =>\n call<FeedbackPost>(`${base}/feedback/${encodeURIComponent(id)}?${qs(me)}`, undefined, signal),\n roadmap: (signal?: AbortSignal) => call<FeedbackRoadmap>(`${base}/feedback/roadmap?${qs(me)}`, undefined, signal),\n changelog: (signal?: AbortSignal) => call<{ entries: ChangelogEntry[] }>(`${base}/feedback/changelog?${qs({ key: c.apiKey })}`, undefined, signal),\n submit: (p: { title: string; body?: string; board: string }) => post<FeedbackPost>(\"/feedback\", p),\n vote: (id: string) => post<{ voted: boolean; votes: number }>(`/feedback/${encodeURIComponent(id)}/vote`, {}),\n comments: (id: string, signal?: AbortSignal) =>\n call<{ comments: FeedbackComment[] }>(`${base}/feedback/${encodeURIComponent(id)}/comments?${qs({ key: c.apiKey })}`, undefined, signal),\n comment: (id: string, body: string) => post<FeedbackComment>(`/feedback/${encodeURIComponent(id)}/comments`, { body }),\n survey: (url: string, signal?: AbortSignal) =>\n call<{ survey: SurveyDefinition | null }>(`${base}/surveys?${qs({ ...me, url })}`, undefined, signal),\n seen: (id: string) => post<unknown>(`/surveys/${encodeURIComponent(id)}/seen`, { user: undefined }),\n respond: (id: string, r: { answers: Record<string, SurveyAnswer>; completed: boolean; seconds: number }) =>\n post<unknown>(`/surveys/${encodeURIComponent(id)}/respond`, r),\n /**\n * One chat by id, else the visitor's newest; `conversations` lists them all. `aiLabel`: the messenger says \"AI agent\"\n * beside an answer's name, so the answer comes without its AI notice line (from 0.22.0).\n */\n chat: (signal?: AbortSignal, conversation?: string) => call<ChatThread>(`${base}/messages?${qs({ ...me, conversation, aiLabel: \"1\" })}`, undefined, signal),\n /**\n * A message; `attachments` are upload ids from `uploadChatFile` (then the body may be empty). `conversation` is\n * the chat it answers, or \"new\" to start one; without it, the running chat or else a new one.\n */\n sendChat: (m: { body: string; conversation?: string; email?: string; url?: string; attachments?: string[]; context?: ChatContext }) => post<ChatThread>(\"/messages\", { ...m, aiLabel: true }),\n /** The visitor read a chat up to `at` (the newest message they saw): MRRocket counts it read on every device and shows \"Seen\" to the team (0.24.0). */\n seenChat: (conversation: string, at: string) => post<{ seenAt: string | null }>(\"/messages/seen\", { conversation, at, user: undefined }),\n /** Uploads one picked file for the next message (pictures and PDFs, at most 10 MB); answers its upload id. */\n uploadChatFile: (file: ChatUpload, signal?: AbortSignal) => {\n const form = new FormData();\n form.append(\"key\", c.apiKey);\n form.append(\"distinctId\", c.distinctId);\n if (c.userHash) form.append(\"userHash\", c.userHash);\n if (\"uri\" in file) form.append(\"file\", file as unknown as Blob);\n else form.append(\"file\", file, (file as Blob & { name?: string }).name || \"file\");\n return call<ChatFile>(withLang(`${base}/messages/attachments`), { method: \"POST\", body: form }, signal);\n },\n /** Where a sent file of this visitor's chat is read (an image's src, a PDF's link). */\n attachmentUrl: (id: string) => `${base}/messages/attachments/${encodeURIComponent(id)}?${qs(me, \"\")}`,\n articles: (q?: string, signal?: AbortSignal) => call<{ articles: ArticleSummary[] }>(`${base}/articles?${qs({ key: c.apiKey, q })}`, undefined, signal),\n /**\n * One article as blocks. `blocks` names the newer kinds of block this widget draws (\"table\", 0.27.0): MRRocket\n * sends those only when asked, so a widget that draws none (older versions, the apps) keeps getting lines of text.\n */\n article: (id: string, signal?: AbortSignal, blocks?: string) =>\n call<Article>(`${base}/articles/${encodeURIComponent(id)}?${qs({ ...me, blocks })}`, undefined, signal),\n messengerLook: (signal?: AbortSignal) => call<MessengerLook>(`${base}/messenger?${qs({ key: c.apiKey })}`, undefined, signal),\n rateArticle: (id: string, helpful: boolean) => post<{ counted: boolean }>(`/articles/${encodeURIComponent(id)}/rate`, { helpful }),\n };\n};\n\nexport type Api = ReturnType<typeof createApi>;\n"],"mappings":";AAIA,SAAS,oBAAoB;AAC7B,SAAS,eAAe,SAAS;AAK1B,IAAM,eAA2C;AAAA,EACpD,IAAI,SAAS;AACT,WAAO,EAAE,cAAc;AAAA,EAC3B;AAAA,EACA,IAAI,UAAU;AACV,WAAO,EAAE,SAAS;AAAA,EACtB;AAAA,EACA,IAAI,WAAW;AACX,WAAO,EAAE,aAAa;AAAA,EAC1B;AAAA,EACA,IAAI,UAAU;AACV,WAAO,EAAE,SAAS;AAAA,EACtB;AACJ;AAgGO,IAAM,kBAAkB,CAAC,aAAa,cAAc,cAAc,aAAa,iBAAiB;AAChG,IAAM,sBAAsB,KAAK,OAAO;AACxC,IAAM,yBAAyB;AAwE/B,IAAM,UAAkH;AAAA,EAC3H,OAAO,EAAE,OAAO,IAAI,QAAQ,IAAI,MAAM,GAAG,MAAM,IAAI,OAAO,GAAG;AAAA,EAC7D,MAAM,EAAE,OAAO,IAAI,QAAQ,IAAI,MAAM,GAAG,MAAM,IAAI,OAAO,GAAG;AAAA,EAC5D,QAAQ,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE;AAC9D;AAyCO,IAAM,YAAY;AAGlB,IAAM,YAAY,CAAC,SACtB,SAAS,YAAY,EAAE,mCAAmC,IAAI,SAAS,QAAQ,EAAE,+BAA+B,IAAI,EAAE,iCAAiC;AAGpJ,IAAM,QAAQ,CAAC,QA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