@eifi1/ui-kit 0.38.1 → 0.39.1
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 +6 -5
- package/dist/auth/auth-errors.d.ts +8 -3
- package/dist/auth/auth-errors.js +3 -1
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/billing/billing-labels.d.ts +25 -2
- package/dist/billing/billing-labels.js +11 -2
- package/dist/billing/billing-labels.js.map +1 -1
- package/dist/billing/billing-overview.d.ts +50 -1
- package/dist/billing/checkout-processing.d.ts +15 -3
- package/dist/billing/checkout-processing.js +3 -1
- package/dist/billing/checkout-processing.js.map +1 -1
- package/dist/billing/pay-page.d.ts +55 -18
- package/dist/billing/pay-page.js +44 -10
- package/dist/billing/pay-page.js.map +1 -1
- package/dist/billing/plan-switch.d.ts +79 -0
- package/dist/billing/plan-switch.js +93 -0
- package/dist/billing/plan-switch.js.map +1 -0
- package/dist/bin/eifi1-pay-page.mjs +109 -21
- package/dist/eslint/index.js +1 -1
- package/dist/i18n/german.js +13 -2
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/locales/en.js +14 -3
- package/dist/i18n/locales/en.js.map +2 -2
- package/dist/i18n/locales/es.js +13 -2
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +13 -2
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +13 -2
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +13 -2
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js +13 -2
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.js +3 -0
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/translation-review.d.ts +11 -0
- package/dist/lib/translation-review.js.map +1 -1
- package/dist/pay/pay.js +102 -40
- package/package.json +1 -1
- package/src/auth/auth-errors.ts +12 -3
- package/src/billing/billing-labels.ts +38 -3
- package/src/billing/billing-overview.ts +53 -1
- package/src/billing/checkout-processing.ts +17 -3
- package/src/billing/pay-page.ts +111 -27
- package/src/billing/plan-switch.tsx +201 -0
- package/src/i18n/german.ts +13 -1
- package/src/i18n/locales/es.ts +12 -1
- package/src/i18n/locales/fr.ts +12 -2
- package/src/i18n/locales/hu.ts +12 -1
- package/src/i18n/locales/it.ts +12 -1
- package/src/i18n/locales/zh.ts +12 -1
- package/src/i18n/review.ts +3 -0
- package/src/index.ts +8 -0
- package/src/lib/translation-review.ts +12 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/translation-review.ts"],"sourcesContent":["/**\n * The pure half of an app's translation review (H1 in docs/i18n-harmonization.md): from\n * the strings the app ships and the verdicts its server stores to one row per (locale,\n * key) with a status — keksdose's `features/translations/translation-catalogue.ts` and\n * kastlan's copy of it, which had grown apart by a fifth status and a second kind of key.\n *\n * WHY THE STRINGS ARE THE CATALOGUE. Nothing on the server lists which strings exist: a\n * verdict only says what somebody thought of one. So the rows are built from what the app\n * ships — its locale bundles, kastlan's document texts, the kit's own words\n * (`kitLabelStrings`) — and the review can never offer a string users do not see. A\n * verdict is stored WITH the wording it was given on, and a string that changed since is\n * noticed by comparing the two: `changed`, read it again, whatever the verdict was.\n *\n * WHAT STAYS IN THE APP. Which locale is read against which (keksdose: everything against\n * English, English against de-CH; kastlan: against German, German against English), where\n * the strings come from, who may review what (the locales and areas its server answers\n * with), and every request. The kit takes those as input and never derives them.\n *\n * camelCase, like the rest of the kit. The contract's wire shape is snake_case\n * (`reference_text`, `reviewer_name`, `reviewed_at`); {@link fromApiReview} and\n * {@link toApiWrite} are the two lines each app would otherwise write — both apps speak\n * the same contract, so the mapping is written once, here.\n */\n\nimport { foldForSearch } from \"./text-match\";\n\n// ── Shapes ──────────────────────────────────────────────────────────────────────\n\nexport type TranslationVerdict = \"APPROVED\" | \"NEEDS_CHANGE\";\n\n/** One stored verdict: what a reviewer said about one string in one locale. */\nexport interface TranslationReview {\n locale: string;\n key: string;\n /** The wording that was judged — compared with today's to notice a change. Empty for\n * a string the locale lacked (a suggested translation for a `missing` row). */\n text: string;\n /** The reference wording at the time. `null` from a server that did not store it. */\n referenceText: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n /** The reviewer's wording — or, for a missing string, the translation to add. */\n suggestion: string | null;\n /** `null` once the reviewer's account has been erased. */\n reviewerName: string | null;\n /** ISO timestamp. */\n reviewedAt: string;\n}\n\n/** What a save sends: the verdict plus the wording it is given on. */\nexport interface TranslationReviewWrite {\n locale: string;\n key: string;\n text: string;\n referenceText: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n suggestion: string | null;\n}\n\n/** What a reset sends: back to \"unreviewed\". */\nexport interface TranslationReviewKey {\n locale: string;\n key: string;\n}\n\n/**\n * Where a string stands, in the order a reviewer works through them: what is not there\n * at all, what nobody has read, what changed after it was read, what was sent back, and\n * what is done. `missing` never occurs for an app whose locales have every key\n * (keksdose); kastlan's French lacks 172 screen texts.\n */\nexport type ReviewStatus = \"missing\" | \"unreviewed\" | \"changed\" | \"needs_change\" | \"approved\";\n\nexport const REVIEW_STATUSES: readonly ReviewStatus[] = [\n \"missing\",\n \"unreviewed\",\n \"changed\",\n \"needs_change\",\n \"approved\",\n];\n\nexport interface TranslationRow {\n /** `${locale}|${key}` — unique across every locale on a page. A bar, not a colon:\n * kastlan's keys contain colons (`common:actions.save`). */\n id: string;\n key: string;\n /** The key's group: `budget` for `budget.rta`, `common` for `common:actions.save`,\n * `kit` for the kit's own words. See {@link keyNamespace}. */\n namespace: string;\n /** Where the string comes from, in the app's own words — kastlan's `screen` and\n * `documents`, keksdose's one source. `\"\"` when the app does not say. */\n source: string;\n locale: string;\n /** The wording users see today; empty when the locale lacks the string. */\n text: string;\n /** The same key in the reference locale. */\n reference: string;\n status: ReviewStatus;\n review: TranslationReview | null;\n /** The interpolations and tags differ from the reference's — `{{count}}` dropped, a\n * `<1>` link lost, a `{date}` renamed. A machine can check that much, so it does,\n * before a person reads. Never set on a missing string: it has nothing to lose. */\n placeholderMismatch: boolean;\n}\n\n// ── The wire contract ───────────────────────────────────────────────────────────\n\n/** A verdict as `GET /translations/reviews` returns it (H1's shared contract). Typed\n * structurally, so an app's generated OpenAPI type fits without a cast. */\nexport interface ApiTranslationReview {\n locale: string;\n key: string;\n text: string;\n reference_text: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n suggestion: string | null;\n reviewer_name: string | null;\n reviewed_at: string;\n}\n\n/** One item of `PUT /translations/reviews`. */\nexport interface ApiTranslationReviewWrite {\n locale: string;\n key: string;\n text: string;\n reference_text: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n suggestion: string | null;\n}\n\n/** A verdict from the server, in the kit's spelling. */\nexport function fromApiReview(review: ApiTranslationReview): TranslationReview {\n return {\n locale: review.locale,\n key: review.key,\n text: review.text,\n referenceText: review.reference_text,\n verdict: review.verdict,\n note: review.note,\n suggestion: review.suggestion,\n reviewerName: review.reviewer_name,\n reviewedAt: review.reviewed_at,\n };\n}\n\n/** A save, in the server's spelling. `TranslationReviewKey` needs no mapping — it is\n * `{ locale, key }` on both sides. */\nexport function toApiWrite(write: TranslationReviewWrite): ApiTranslationReviewWrite {\n return {\n locale: write.locale,\n key: write.key,\n text: write.text,\n reference_text: write.referenceText,\n verdict: write.verdict,\n note: write.note,\n suggestion: write.suggestion,\n };\n}\n\n// ── Strings ─────────────────────────────────────────────────────────────────────\n\n/**\n * A nested bundle as `key → string`, in the bundle's own order. Non-string leaves are\n * skipped rather than stringified into something nobody wrote.\n *\n * `prefix` is put in front of every key AS IS, so it names the separator too:\n * `flattenStrings(bundle)` is keksdose's `budget.rta`, `flattenStrings(tree, \"common:\")`\n * kastlan's `common:actions.save`, and `flattenStrings(kitLabelStrings(labels), \"kit.\")`\n * the kit's own words as `kit.combobox.resultCount(3)` — already flat, so only the prefix\n * is added.\n */\nexport function flattenStrings(tree: Readonly<Record<string, unknown>>, prefix = \"\"): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(tree)) {\n const path = `${prefix}${key}`;\n if (typeof value === \"string\") out[path] = value;\n else if (value && typeof value === \"object\" && !Array.isArray(value)) {\n Object.assign(out, flattenStrings(value as Record<string, unknown>, `${path}.`));\n }\n }\n return out;\n}\n\n/**\n * The key's group, for the namespace filter: the part before a colon when there is one\n * (kastlan's `common:actions.save` → `common`, `doc_text.invoice:due` →\n * `doc_text.invoice`), else the first dotted segment (keksdose's `budget.rta` →\n * `budget`, the kit's `kit.combobox.resultCount(3)` → `kit`). Only the part before a\n * sample's `(` is looked at, so a colon inside one cannot move the split.\n */\nexport function keyNamespace(key: string): string {\n const head = key.split(\"(\", 1)[0];\n const colon = head.indexOf(\":\");\n return colon >= 0 ? head.slice(0, colon) : head.split(\".\", 1)[0];\n}\n\n// i18next `{{x}}` (formatting options ignored: `{{x, number}}` is `{{x}}`); a Python\n// format field `{x}` / `{0}` / `{amount:.2f}` (kastlan's document texts), but not a\n// LaTeX argument (`\\textbf{x}` — a letter or backslash right before the brace); a\n// numbered or named tag (`<1>`, `<strong>`), not prose in angle brackets (\"<deleted\n// user>\"); and a nested `$t(key)`. `{{x}}` is tried first at its position and consumed\n// whole, so it is never counted a second time as `{x}`.\nconst PLACEHOLDER_RE =\n /\\{\\{\\s*([^}\\s,]+)[^}]*\\}\\}|(?<![\\\\A-Za-z])\\{([a-z_][a-z0-9_]*|\\d+)(?:[!:][^{}]*)?\\}|<\\/?(\\d+|[a-z][a-z0-9]*)\\s*\\/?>|\\$t\\(([^)]+)\\)/g;\n\n/** The placeholders in a string, as a sorted multiset: `{{count}}`, `{date}`, `<1>`,\n * `$t(common.save)`. */\nexport function placeholderTokens(text: string): string[] {\n const found: string[] = [];\n for (const m of text.matchAll(PLACEHOLDER_RE)) {\n if (m[1]) found.push(`{{${m[1]}}}`);\n // `{ref:retention}` (ui-kit 0.28's legal cross-reference) keeps its target: a\n // translation that points at another section changed what the sentence says. Every\n // other `{x:spec}` is a format spec, which a translation may change.\n else if (m[2]) found.push(m[2] === \"ref\" ? m[0] : `{${m[2]}}`);\n else if (m[3]) found.push(`<${m[3]}>`);\n else if (m[4]) found.push(`$t(${m[4]})`);\n }\n return found.sort();\n}\n\n/** Whether `text` has other placeholders than `reference` — dropped, renamed or added.\n * Moving one is fine: a translation reorders a sentence. */\nexport function placeholderMismatch(text: string, reference: string): boolean {\n const a = placeholderTokens(text);\n const b = placeholderTokens(reference);\n return a.length !== b.length || a.some((p, i) => p !== b[i]);\n}\n\n// ── Status ──────────────────────────────────────────────────────────────────────\n\n/**\n * A verdict counts only for the wording it was given on. If the string or its reference\n * changed since, it is `changed` — read it again — whatever the verdict was. A string the\n * locale lacks is `missing` until somebody suggests its translation (stored as\n * NEEDS_CHANGE on the empty text, so it reads `needs_change`, and `changed` once a\n * developer adds the string).\n */\nexport function reviewStatus(\n review: TranslationReview | null | undefined,\n text: string,\n reference: string,\n): ReviewStatus {\n if (!review) return text === \"\" && reference !== \"\" ? \"missing\" : \"unreviewed\";\n if (review.text !== text) return \"changed\";\n if (review.referenceText != null && review.referenceText !== reference) return \"changed\";\n return review.verdict === \"APPROVED\" ? \"approved\" : \"needs_change\";\n}\n\n/**\n * Whether `key` lies in `area`: the key IS the area, or sits under it — `legal.terms`\n * and kastlan's `legal:terms` are in `legal`, `legalese.title` is not.\n *\n * 0.28: the kit's own words of that area too — `kit.legal.sections.terms.law.body(…)`\n * is in `legal`. All three apps list the kit's labels under `kit.`\n * (`flattenStrings(kitLabelStrings(labels), \"kit.\")`), and since 0.28 the kit writes\n * the shared legal sections, so a lawyer with a `[\"legal\"]` grant who was not shown\n * `kit.legal.*` would not see half of the Privacy Policy — and the server would refuse\n * the verdicts (docs/legal-harmonization.md §7.5). server-kit's `in_areas` and the apps'\n * copies of it apply the same rule.\n */\nexport function keyInArea(key: string, area: string): boolean {\n return (\n key === area || key.startsWith(`${area}.`) || key.startsWith(`${area}:`) || key.startsWith(`kit.${area}.`)\n );\n}\n\n/**\n * The area of `areas` that `key` lies in ({@link keyInArea}), or `undefined` — the\n * translation page's grouping by the same rule the filter and the server use, so\n * `kit.legal.sections.privacy.rights.lead` is grouped under `legal` with the app's own\n * legal texts instead of under `kit.legal`:\n *\n * const namespaceOf = (key: string) => reviewAreaOf(key, [\"legal\"]) ?? ownNamespaceOf(key);\n *\n * Where two areas both hold the key (`legal` and `legal.privacy`), the longer — the more\n * specific — wins, whatever their order. `inArea` is the app's own rule, as for\n * {@link keyInAreas}.\n */\nexport function reviewAreaOf(\n key: string,\n areas: readonly string[],\n inArea: (key: string, area: string) => boolean = keyInArea,\n): string | undefined {\n let found: string | undefined;\n for (const area of areas) {\n if (inArea(key, area) && (found === undefined || area.length > found.length)) found = area;\n }\n return found;\n}\n\n/**\n * Whether `key` lies in one of `areas` — the scope a reviewer may be limited to\n * (keksdose: `[\"legal\"]`, a lawyer who judges the Imprint, the Privacy Policy and the\n * Terms and sees nothing else). `null`/`undefined` is every area. The server applies the\n * same rule and refuses verdicts outside; this decides only what is listed.\n */\nexport function keyInAreas(\n key: string,\n areas: readonly string[] | null | undefined,\n inArea: (key: string, area: string) => boolean = keyInArea,\n): boolean {\n return !areas || areas.some((area) => inArea(key, area));\n}\n\nexport interface TranslationRowsInput {\n locale: string;\n /** The locale's strings, `key → text` ({@link flattenStrings}). */\n strings: Readonly<Record<string, string>>;\n /** The reference locale's strings — whichever locale THIS app reads `locale` against. */\n reference: Readonly<Record<string, string>>;\n /** The verdicts: this locale's by key, or the whole list as the server sent it (other\n * locales' verdicts are skipped). */\n reviews?: ReadonlyMap<string, TranslationReview> | readonly TranslationReview[];\n /** Default {@link keyNamespace}. */\n namespaceOf?: (key: string) => string;\n /** The row's source, an app-defined word (kastlan: `doc_text.` keys are `documents`,\n * the rest `screen`). Default: none (`\"\"`). */\n sourceOf?: (key: string) => string;\n /** Keep only keys inside these areas ({@link keyInAreas}); `null` keeps every key. */\n areas?: readonly string[] | null;\n /** Default {@link keyInArea}. */\n inArea?: (key: string, area: string) => boolean;\n}\n\n/**\n * Every key of one locale, with its status: the reference's keys first, in its order, so\n * rows read the way the app's authors wrote them; a key only this locale has is appended\n * rather than dropped (a parity test should forbid it, but the page should not lie if one\n * slips through).\n */\nexport function translationRows({\n locale,\n strings,\n reference,\n reviews,\n namespaceOf: groupOf = keyNamespace,\n sourceOf,\n areas,\n inArea,\n}: TranslationRowsInput): TranslationRow[] {\n const byKey = new Map<string, TranslationReview>();\n if (reviews instanceof Map) {\n for (const [key, review] of reviews) byKey.set(key, review);\n } else if (reviews) {\n for (const review of reviews as readonly TranslationReview[]) {\n if (review.locale === locale) byKey.set(review.key, review);\n }\n }\n const keys = Object.keys(reference);\n for (const key of Object.keys(strings)) if (!(key in reference)) keys.push(key);\n return keys\n .filter((key) => keyInAreas(key, areas, inArea))\n .map((key) => {\n const text = strings[key] ?? \"\";\n const ref = reference[key] ?? \"\";\n const review = byKey.get(key) ?? null;\n return {\n id: `${locale}|${key}`,\n key,\n namespace: groupOf(key),\n source: sourceOf?.(key) ?? \"\",\n locale,\n text,\n reference: ref,\n status: reviewStatus(review, text, ref),\n review,\n placeholderMismatch: text !== \"\" && placeholderMismatch(text, ref),\n };\n });\n}\n\n/** How many rows stand where, and how many there are. */\nexport type TranslationSummary = Record<ReviewStatus, number> & { total: number };\n\nexport function summariseRows(rows: readonly TranslationRow[]): TranslationSummary {\n const summary: TranslationSummary = {\n missing: 0,\n unreviewed: 0,\n changed: 0,\n needs_change: 0,\n approved: 0,\n total: rows.length,\n };\n for (const row of rows) summary[row.status] += 1;\n return summary;\n}\n\n// ── Filtering ───────────────────────────────────────────────────────────────────\n\n/** The panel's filters. `\"all\"` switches one off. */\nexport interface TranslationReviewFilter {\n status: ReviewStatus | \"all\";\n source: string;\n namespace: string;\n /** Searched in the key, the text and the reference, folded as every kit list's search\n * is (`foldForSearch`): no case, no accents — \"uberweisung\" finds \"Überweisung\". */\n query: string;\n placeholdersOnly: boolean;\n}\n\nexport const DEFAULT_TRANSLATION_REVIEW_FILTER: TranslationReviewFilter = {\n status: \"all\",\n source: \"all\",\n namespace: \"all\",\n query: \"\",\n placeholdersOnly: false,\n};\n\nexport function filterTranslationRows(\n rows: readonly TranslationRow[],\n filter: Partial<TranslationReviewFilter>,\n): TranslationRow[] {\n const f = { ...DEFAULT_TRANSLATION_REVIEW_FILTER, ...filter };\n // Folded as every kit list's search is (DUP-5, refactor audit 2026-10).\n const q = foldForSearch(f.query.trim());\n return rows.filter(\n (row) =>\n (f.status === \"all\" || row.status === f.status) &&\n (f.source === \"all\" || row.source === f.source) &&\n (f.namespace === \"all\" || row.namespace === f.namespace) &&\n (!f.placeholdersOnly || row.placeholderMismatch) &&\n (!q || [row.key, row.text, row.reference].some((s) => foldForSearch(s).includes(q))),\n );\n}\n\n// ── Grouping ────────────────────────────────────────────────────────────────────\n\n/** One group of rows — an area, a source — and how they stand. */\nexport interface TranslationRowGroup {\n key: string;\n rows: TranslationRow[];\n summary: TranslationSummary;\n}\n\n/**\n * Rows in groups, each group where its first row is — the reference's order, so the areas\n * read the way the app's authors wrote the bundle — and each group's rows in their own\n * order. keksdose live #377: a reviewer on a phone works area by area (\"the budget\n * strings, then the legal ones\"), and a flat list of 3859 rows is not a way to see\n * where an area stands.\n *\n * `groupOf` names a row's group: `(row) => row.namespace` for the areas,\n * `(row) => row.source` for kastlan's screen texts and documents.\n */\nexport function groupTranslationRows(\n rows: readonly TranslationRow[],\n groupOf: (row: TranslationRow) => string,\n): TranslationRowGroup[] {\n const byKey = new Map<string, TranslationRow[]>();\n for (const row of rows) {\n const key = groupOf(row);\n const list = byKey.get(key);\n if (list) list.push(row);\n else byKey.set(key, [row]);\n }\n return [...byKey].map(([key, list]) => ({ key, rows: list, summary: summariseRows(list) }));\n}\n\n/**\n * The rows a group's \"Approve the unreviewed\" takes: the ones nobody has given a verdict\n * and that have a text. Not `changed` — a string that moved since it was judged asks to\n * be READ again, which a bulk action is the opposite of — and not `missing`, which has\n * nothing to approve.\n */\nexport function unreviewedRows(rows: readonly TranslationRow[]): TranslationRow[] {\n return rows.filter((row) => row.status === \"unreviewed\" && row.text !== \"\");\n}\n\n// ── Writing ─────────────────────────────────────────────────────────────────────\n\n/** What gets stored for a verdict: the wording it was given on, so a later change of the\n * string (or of its reference) shows up as `changed`. */\nexport function reviewWrite(\n row: TranslationRow,\n verdict: TranslationVerdict,\n note: string | null = null,\n suggestion: string | null = null,\n): TranslationReviewWrite {\n return {\n locale: row.locale,\n key: row.key,\n text: row.text,\n referenceText: row.reference,\n verdict,\n note,\n suggestion,\n };\n}\n\n/** What takes a set of verdicts back: see {@link reviewUndo}. */\nexport interface TranslationReviewUndo {\n /** The verdicts the rows had before, to store again — each on the wording it was\n * given on, so a row that was `changed` reads `changed` again. */\n writes: TranslationReviewWrite[];\n /** The rows that had no verdict before: back to unreviewed. */\n clears: TranslationReviewKey[];\n}\n\n/**\n * How to take back what was just said about `rows` — the rows AS THEY WERE before the\n * write, with the verdicts they carried then. The panel's Undo toast (0.25, keksdose live\n * #377) runs it: a swipe on a phone approves in one movement, and a movement can be a\n * mistake.\n *\n * A row that had a verdict gets it stored again (its note, its suggestion, the wording it\n * was judged on); one that had none is cleared. The server stamps the restored verdict\n * with the person undoing and the time, as it stamps every write — the contract has no\n * way to write a verdict in somebody else's name, and should not.\n */\nexport function reviewUndo(rows: readonly TranslationRow[]): TranslationReviewUndo {\n const writes: TranslationReviewWrite[] = [];\n const clears: TranslationReviewKey[] = [];\n for (const row of rows) {\n const before = row.review;\n if (!before) {\n clears.push({ locale: row.locale, key: row.key });\n continue;\n }\n writes.push({\n locale: row.locale,\n key: row.key,\n text: before.text,\n referenceText: before.referenceText,\n verdict: before.verdict,\n note: before.note,\n suggestion: before.suggestion,\n });\n }\n return { writes, clears };\n}\n\n/** The app's cached verdict list with `written` in place of what was said before — a\n * save answers with the rows it wrote, so a page patches its copy instead of\n * downloading every verdict again after each click. Any spelling with `locale` and\n * `key` (the API's or the kit's). */\nexport function mergeReviews<T extends TranslationReviewKey>(prev: readonly T[], written: readonly T[]): T[] {\n const id = (r: TranslationReviewKey) => `${r.locale}|${r.key}`;\n const replaced = new Set(written.map(id));\n return [...prev.filter((r) => !replaced.has(id(r))), ...written];\n}\n\n/** The cached list without the verdicts on `cleared`. */\nexport function dropReviews<T extends TranslationReviewKey>(\n prev: readonly T[],\n cleared: readonly TranslationReviewKey[],\n): T[] {\n const gone = new Set(cleared.map((r) => `${r.locale}|${r.key}`));\n return prev.filter((r) => !gone.has(`${r.locale}|${r.key}`));\n}\n\n// ── Swipe bindings ──────────────────────────────────────────────────────────────\n\n/**\n * What a phone card's swipe can be bound to in `TranslationReviewPanel`'s `swipe`\n * (keksdose — Marcel's live #377 rework, 2026-10-03: *\"Add the swipe options to be shown\n * also to the settings /settings#interaction area where the other swipe options are\n * defined\"*). keksdose lets the user bind every list's swipes there — per side, a primary\n * action at the first threshold and a secondary one at a longer drag — and lists each\n * surface's ids in its `SWIPE_ACTIONS`; this is the translation list's, in the order a\n * settings page offers them.\n *\n * - `approve` — the string is right as it stands. With the panel's Undo toast.\n * - `edit` — open the editor with the cursor in the wording: \"Needs a change\" (or\n * \"Suggest translation\" on a missing string). Writes nothing; the editor does.\n * - `clear` — take the verdict back: unreviewed again. With the Undo toast, which stores\n * the verdict again.\n *\n * THERE IS NO SEPARATE \"needs a change\". The editor has no verdict to preselect: Approve\n * and \"Needs a change\" stand side by side in it, and \"Needs a change\" takes a note or a\n * different wording — a verdict without either tells whoever fixes the string nothing, so\n * a swipe never sends one blind (0.25). The one honest thing a \"needs a change\" swipe can\n * do is therefore open the editor with the cursor in the wording — which is `edit`, and\n * `edit` already says \"Needs a change\" on the card. A second id doing the same would arm\n * a second threshold that does what the first already did: the duplicate keksdose's\n * `resolveSwipePlan` drops for exactly that reason.\n */\nexport const TRANSLATION_REVIEW_SWIPE_ACTIONS = [\"approve\", \"edit\", \"clear\"] as const;\n\n/** One of {@link TRANSLATION_REVIEW_SWIPE_ACTIONS}. */\nexport type TranslationReviewSwipeAction = (typeof TRANSLATION_REVIEW_SWIPE_ACTIONS)[number];\n\n/**\n * Which swipe does what on a phone card — `TranslationReviewPanel`'s `swipe`. Each side is\n * an ordered ladder, exactly as `SwipeableRow` and DataTable's `mobileSwipeActions` model\n * one: index 0 commits at the first threshold, index 1 at the longer drag (and so on — the\n * thresholds spread evenly over the card's width). A side left out, or empty, does not\n * swipe.\n *\n * LOGICAL SIDES: `end` is a drag toward the reading end of the line — right in a\n * left-to-right page, left in a right-to-left one — and `start` the other way, so one\n * binding holds in both directions. An app whose settings store physical sides (keksdose's\n * `right`/`left`) hands `right` as `end` for a left-to-right page.\n */\nexport interface TranslationReviewSwipeBinding {\n /** A drag toward the reading START, nearest threshold first. */\n start?: readonly TranslationReviewSwipeAction[];\n /** A drag toward the reading END, nearest threshold first. */\n end?: readonly TranslationReviewSwipeAction[];\n}\n\n/** What `swipe={true}` means — 0.25's fixed mapping: approve toward the end, open the\n * editor (\"Needs a change\") toward the start. A settings page's \"reset\" goes back here. */\nexport const DEFAULT_TRANSLATION_REVIEW_SWIPE: TranslationReviewSwipeBinding = Object.freeze({\n start: Object.freeze([\"edit\"] as const),\n end: Object.freeze([\"approve\"] as const),\n});\n\n/** The ladders one row actually offers, from a {@link TranslationReviewSwipeBinding}. */\nexport interface TranslationReviewSwipePlan {\n start: TranslationReviewSwipeAction[];\n end: TranslationReviewSwipeAction[];\n}\n\n/**\n * The binding resolved against one row — keksdose's `resolveSwipePlan`, for this list.\n * An id the row cannot offer DROPS OUT and the ladder closes up behind it, so the second\n * stage becomes the first rather than the side going dead behind an unreachable first\n * stage (or arming a threshold that does nothing):\n *\n * - `approve`: not on a missing string (nothing to approve) or an approved one (it would\n * say it again) — the rows that have no approve button either;\n * - `clear`: not without `canClear` (the app passed no `onClear`), and not on a row with\n * no verdict to take back (unreviewed; missing with no suggestion);\n * - `edit`: on every row;\n * - an id named twice on one side: the second time (a longer drag to the same effect);\n * - an id this version does not know (a binding stored by another version, an app's own\n * \"none\" slot): dropped like one that does not apply.\n *\n * Only what the ROW decides. Whether the panel may write at all — `readOnly`, no\n * `onSave`, a write lock, the row's own write still out — is the panel's, and then no\n * side swipes.\n */\nexport function translationReviewSwipePlan(\n binding: TranslationReviewSwipeBinding,\n row: TranslationRow,\n { canClear = false }: { canClear?: boolean } = {},\n): TranslationReviewSwipePlan {\n const offers = (id: TranslationReviewSwipeAction): boolean => {\n switch (id) {\n case \"approve\":\n return row.text !== \"\" && row.status !== \"approved\";\n case \"edit\":\n return true;\n case \"clear\":\n return canClear && row.review !== null;\n default:\n return false;\n }\n };\n const side = (ids: readonly TranslationReviewSwipeAction[] | undefined): TranslationReviewSwipeAction[] => {\n const out: TranslationReviewSwipeAction[] = [];\n for (const id of ids ?? []) {\n if (!out.includes(id) && offers(id)) out.push(id);\n }\n return out;\n };\n return { start: side(binding.start), end: side(binding.end) };\n}\n\n// ── Export ──────────────────────────────────────────────────────────────────────\n\n/**\n * One entry of the \"Export corrections\" file — enough for a developer to apply the change\n * to the bundle without opening the page. snake_case `reviewed_at` on purpose: this is a\n * FILE, the one keksdose and kastlan already write, beside an API spelled that way.\n */\nexport interface TranslationCorrection {\n locale: string;\n key: string;\n status: ReviewStatus;\n current: string;\n reference: string;\n suggestion: string | null;\n note: string | null;\n reviewer: string | null;\n reviewed_at: string | null;\n}\n\n/** The rows sent back (verdict NEEDS_CHANGE — a suggested translation for a missing\n * string included), as the export file lists them. */\nexport function translationCorrections(rows: readonly TranslationRow[]): TranslationCorrection[] {\n return rows\n .filter((row) => row.review?.verdict === \"NEEDS_CHANGE\")\n .map((row) => ({\n locale: row.locale,\n key: row.key,\n status: row.status,\n current: row.text,\n reference: row.reference,\n suggestion: row.review?.suggestion ?? null,\n note: row.review?.note ?? null,\n reviewer: row.review?.reviewerName ?? null,\n reviewed_at: row.review?.reviewedAt ?? null,\n }));\n}\n"],"mappings":";AAwBA,SAAS,qBAAqB;AAkDvB,MAAM,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AAM,mCAAkE,OAAO,OAAO;AAAA,EAC3F,OAAO,OAAO,OAAO,CAAC,MAAM,CAAU;AAAA,EACtC,KAAK,OAAO,OAAO,CAAC,SAAS,CAAU;AACzC,CAAC;AA2BM,SAAS,2BACd,SACA,KACA,EAAE,WAAW,MAAM,IAA4B,CAAC,GACpB;AAC5B,QAAM,SAAS,CAAC,OAA8C;AAC5D,YAAQ,IAAI;AAAA,MACV,KAAK;AACH,eAAO,IAAI,SAAS,MAAM,IAAI,WAAW;AAAA,MAC3C,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO,YAAY,IAAI,WAAW;AAAA,MACpC;AACE,eAAO;AAAA,IACX;AAAA,EACF;AACA,QAAM,OAAO,CAAC,QAA6F;AACzG,UAAM,MAAsC,CAAC;AAC7C,eAAW,MAAM,OAAO,CAAC,GAAG;AAC1B,UAAI,CAAC,IAAI,SAAS,EAAE,KAAK,OAAO,EAAE,EAAG,KAAI,KAAK,EAAE;AAAA,IAClD;AACA,WAAO;AAAA,EACT;AACA,SAAO,EAAE,OAAO,KAAK,QAAQ,KAAK,GAAG,KAAK,KAAK,QAAQ,GAAG,EAAE;AAC9D;AAuBO,SAAS,uBAAuB,MAA0D;AAC/F,SAAO,KACJ,OAAO,CAAC,QAAQ,IAAI,QAAQ,YAAY,cAAc,EACtD,IAAI,CAAC,SAAS;AAAA,IACb,QAAQ,IAAI;AAAA,IACZ,KAAK,IAAI;AAAA,IACT,QAAQ,IAAI;AAAA,IACZ,SAAS,IAAI;AAAA,IACb,WAAW,IAAI;AAAA,IACf,YAAY,IAAI,QAAQ,cAAc;AAAA,IACtC,MAAM,IAAI,QAAQ,QAAQ;AAAA,IAC1B,UAAU,IAAI,QAAQ,gBAAgB;AAAA,IACtC,aAAa,IAAI,QAAQ,cAAc;AAAA,EACzC,EAAE;AACN;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/translation-review.ts"],"sourcesContent":["/**\n * The pure half of an app's translation review (H1 in docs/i18n-harmonization.md): from\n * the strings the app ships and the verdicts its server stores to one row per (locale,\n * key) with a status — keksdose's `features/translations/translation-catalogue.ts` and\n * kastlan's copy of it, which had grown apart by a fifth status and a second kind of key.\n *\n * WHY THE STRINGS ARE THE CATALOGUE. Nothing on the server lists which strings exist: a\n * verdict only says what somebody thought of one. So the rows are built from what the app\n * ships — its locale bundles, kastlan's document texts, the kit's own words\n * (`kitLabelStrings`) — and the review can never offer a string users do not see. A\n * verdict is stored WITH the wording it was given on, and a string that changed since is\n * noticed by comparing the two: `changed`, read it again, whatever the verdict was.\n *\n * WHAT STAYS IN THE APP. Which locale is read against which (keksdose: everything against\n * English, English against de-CH; kastlan: against German, German against English), where\n * the strings come from, who may review what (the locales and areas its server answers\n * with), and every request. The kit takes those as input and never derives them.\n *\n * camelCase, like the rest of the kit. The contract's wire shape is snake_case\n * (`reference_text`, `reviewer_name`, `reviewed_at`); {@link fromApiReview} and\n * {@link toApiWrite} are the two lines each app would otherwise write — both apps speak\n * the same contract, so the mapping is written once, here.\n */\n\nimport { foldForSearch } from \"./text-match\";\n\n// ── Shapes ──────────────────────────────────────────────────────────────────────\n\nexport type TranslationVerdict = \"APPROVED\" | \"NEEDS_CHANGE\";\n\n/** One stored verdict: what a reviewer said about one string in one locale. */\nexport interface TranslationReview {\n locale: string;\n key: string;\n /** The wording that was judged — compared with today's to notice a change. Empty for\n * a string the locale lacked (a suggested translation for a `missing` row). */\n text: string;\n /** The reference wording at the time. `null` from a server that did not store it. */\n referenceText: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n /** The reviewer's wording — or, for a missing string, the translation to add. */\n suggestion: string | null;\n /** `null` once the reviewer's account has been erased. */\n reviewerName: string | null;\n /** ISO timestamp. */\n reviewedAt: string;\n}\n\n/** What a save sends: the verdict plus the wording it is given on. */\nexport interface TranslationReviewWrite {\n locale: string;\n key: string;\n text: string;\n referenceText: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n suggestion: string | null;\n}\n\n/** What a reset sends: back to \"unreviewed\". */\nexport interface TranslationReviewKey {\n locale: string;\n key: string;\n}\n\n/**\n * Where a string stands, in the order a reviewer works through them: what is not there\n * at all, what nobody has read, what changed after it was read, what was sent back, and\n * what is done. `missing` never occurs for an app whose locales have every key\n * (keksdose); kastlan's French lacks 172 screen texts.\n */\nexport type ReviewStatus = \"missing\" | \"unreviewed\" | \"changed\" | \"needs_change\" | \"approved\";\n\nexport const REVIEW_STATUSES: readonly ReviewStatus[] = [\n \"missing\",\n \"unreviewed\",\n \"changed\",\n \"needs_change\",\n \"approved\",\n];\n\nexport interface TranslationRow {\n /** `${locale}|${key}` — unique across every locale on a page. A bar, not a colon:\n * kastlan's keys contain colons (`common:actions.save`). */\n id: string;\n key: string;\n /** The key's group: `budget` for `budget.rta`, `common` for `common:actions.save`,\n * `kit` for the kit's own words. See {@link keyNamespace}. */\n namespace: string;\n /** Where the string comes from, in the app's own words — kastlan's `screen` and\n * `documents`, keksdose's one source. `\"\"` when the app does not say. */\n source: string;\n locale: string;\n /** The wording users see today; empty when the locale lacks the string. */\n text: string;\n /** The same key in the reference locale. */\n reference: string;\n status: ReviewStatus;\n review: TranslationReview | null;\n /** The interpolations and tags differ from the reference's — `{{count}}` dropped, a\n * `<1>` link lost, a `{date}` renamed. A machine can check that much, so it does,\n * before a person reads. Never set on a missing string: it has nothing to lose. */\n placeholderMismatch: boolean;\n}\n\n// ── The wire contract ───────────────────────────────────────────────────────────\n\n/** A verdict as `GET /translations/reviews` returns it (H1's shared contract). Typed\n * structurally, so an app's generated OpenAPI type fits without a cast. */\nexport interface ApiTranslationReview {\n locale: string;\n key: string;\n text: string;\n reference_text: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n suggestion: string | null;\n reviewer_name: string | null;\n /** server-kit 0.10: the name's two parts (`reviewer_name` is them in the reader's order). */\n reviewer_first_name?: string | null;\n reviewer_last_name?: string | null;\n reviewed_at: string;\n}\n\n/** `GET /translations/reviews` (server-kit `TranslationReviewsResponse`): the locales and\n * areas the caller may review (`areas` null: every area; `[\"kit\"]` for a review token)\n * and every stored verdict in them. Typed structurally, as {@link ApiTranslationReview}. */\nexport interface ApiTranslationReviewsResponse {\n locales: string[];\n areas?: string[] | null;\n reviews: ApiTranslationReview[];\n}\n\n/** One item of `PUT /translations/reviews`. */\nexport interface ApiTranslationReviewWrite {\n locale: string;\n key: string;\n text: string;\n reference_text: string | null;\n verdict: TranslationVerdict;\n note: string | null;\n suggestion: string | null;\n}\n\n/** A verdict from the server, in the kit's spelling. */\nexport function fromApiReview(review: ApiTranslationReview): TranslationReview {\n return {\n locale: review.locale,\n key: review.key,\n text: review.text,\n referenceText: review.reference_text,\n verdict: review.verdict,\n note: review.note,\n suggestion: review.suggestion,\n reviewerName: review.reviewer_name,\n reviewedAt: review.reviewed_at,\n };\n}\n\n/** A save, in the server's spelling. `TranslationReviewKey` needs no mapping — it is\n * `{ locale, key }` on both sides. */\nexport function toApiWrite(write: TranslationReviewWrite): ApiTranslationReviewWrite {\n return {\n locale: write.locale,\n key: write.key,\n text: write.text,\n reference_text: write.referenceText,\n verdict: write.verdict,\n note: write.note,\n suggestion: write.suggestion,\n };\n}\n\n// ── Strings ─────────────────────────────────────────────────────────────────────\n\n/**\n * A nested bundle as `key → string`, in the bundle's own order. Non-string leaves are\n * skipped rather than stringified into something nobody wrote.\n *\n * `prefix` is put in front of every key AS IS, so it names the separator too:\n * `flattenStrings(bundle)` is keksdose's `budget.rta`, `flattenStrings(tree, \"common:\")`\n * kastlan's `common:actions.save`, and `flattenStrings(kitLabelStrings(labels), \"kit.\")`\n * the kit's own words as `kit.combobox.resultCount(3)` — already flat, so only the prefix\n * is added.\n */\nexport function flattenStrings(tree: Readonly<Record<string, unknown>>, prefix = \"\"): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(tree)) {\n const path = `${prefix}${key}`;\n if (typeof value === \"string\") out[path] = value;\n else if (value && typeof value === \"object\" && !Array.isArray(value)) {\n Object.assign(out, flattenStrings(value as Record<string, unknown>, `${path}.`));\n }\n }\n return out;\n}\n\n/**\n * The key's group, for the namespace filter: the part before a colon when there is one\n * (kastlan's `common:actions.save` → `common`, `doc_text.invoice:due` →\n * `doc_text.invoice`), else the first dotted segment (keksdose's `budget.rta` →\n * `budget`, the kit's `kit.combobox.resultCount(3)` → `kit`). Only the part before a\n * sample's `(` is looked at, so a colon inside one cannot move the split.\n */\nexport function keyNamespace(key: string): string {\n const head = key.split(\"(\", 1)[0];\n const colon = head.indexOf(\":\");\n return colon >= 0 ? head.slice(0, colon) : head.split(\".\", 1)[0];\n}\n\n// i18next `{{x}}` (formatting options ignored: `{{x, number}}` is `{{x}}`); a Python\n// format field `{x}` / `{0}` / `{amount:.2f}` (kastlan's document texts), but not a\n// LaTeX argument (`\\textbf{x}` — a letter or backslash right before the brace); a\n// numbered or named tag (`<1>`, `<strong>`), not prose in angle brackets (\"<deleted\n// user>\"); and a nested `$t(key)`. `{{x}}` is tried first at its position and consumed\n// whole, so it is never counted a second time as `{x}`.\nconst PLACEHOLDER_RE =\n /\\{\\{\\s*([^}\\s,]+)[^}]*\\}\\}|(?<![\\\\A-Za-z])\\{([a-z_][a-z0-9_]*|\\d+)(?:[!:][^{}]*)?\\}|<\\/?(\\d+|[a-z][a-z0-9]*)\\s*\\/?>|\\$t\\(([^)]+)\\)/g;\n\n/** The placeholders in a string, as a sorted multiset: `{{count}}`, `{date}`, `<1>`,\n * `$t(common.save)`. */\nexport function placeholderTokens(text: string): string[] {\n const found: string[] = [];\n for (const m of text.matchAll(PLACEHOLDER_RE)) {\n if (m[1]) found.push(`{{${m[1]}}}`);\n // `{ref:retention}` (ui-kit 0.28's legal cross-reference) keeps its target: a\n // translation that points at another section changed what the sentence says. Every\n // other `{x:spec}` is a format spec, which a translation may change.\n else if (m[2]) found.push(m[2] === \"ref\" ? m[0] : `{${m[2]}}`);\n else if (m[3]) found.push(`<${m[3]}>`);\n else if (m[4]) found.push(`$t(${m[4]})`);\n }\n return found.sort();\n}\n\n/** Whether `text` has other placeholders than `reference` — dropped, renamed or added.\n * Moving one is fine: a translation reorders a sentence. */\nexport function placeholderMismatch(text: string, reference: string): boolean {\n const a = placeholderTokens(text);\n const b = placeholderTokens(reference);\n return a.length !== b.length || a.some((p, i) => p !== b[i]);\n}\n\n// ── Status ──────────────────────────────────────────────────────────────────────\n\n/**\n * A verdict counts only for the wording it was given on. If the string or its reference\n * changed since, it is `changed` — read it again — whatever the verdict was. A string the\n * locale lacks is `missing` until somebody suggests its translation (stored as\n * NEEDS_CHANGE on the empty text, so it reads `needs_change`, and `changed` once a\n * developer adds the string).\n */\nexport function reviewStatus(\n review: TranslationReview | null | undefined,\n text: string,\n reference: string,\n): ReviewStatus {\n if (!review) return text === \"\" && reference !== \"\" ? \"missing\" : \"unreviewed\";\n if (review.text !== text) return \"changed\";\n if (review.referenceText != null && review.referenceText !== reference) return \"changed\";\n return review.verdict === \"APPROVED\" ? \"approved\" : \"needs_change\";\n}\n\n/**\n * Whether `key` lies in `area`: the key IS the area, or sits under it — `legal.terms`\n * and kastlan's `legal:terms` are in `legal`, `legalese.title` is not.\n *\n * 0.28: the kit's own words of that area too — `kit.legal.sections.terms.law.body(…)`\n * is in `legal`. All three apps list the kit's labels under `kit.`\n * (`flattenStrings(kitLabelStrings(labels), \"kit.\")`), and since 0.28 the kit writes\n * the shared legal sections, so a lawyer with a `[\"legal\"]` grant who was not shown\n * `kit.legal.*` would not see half of the Privacy Policy — and the server would refuse\n * the verdicts (docs/legal-harmonization.md §7.5). server-kit's `in_areas` and the apps'\n * copies of it apply the same rule.\n */\nexport function keyInArea(key: string, area: string): boolean {\n return (\n key === area || key.startsWith(`${area}.`) || key.startsWith(`${area}:`) || key.startsWith(`kit.${area}.`)\n );\n}\n\n/**\n * The area of `areas` that `key` lies in ({@link keyInArea}), or `undefined` — the\n * translation page's grouping by the same rule the filter and the server use, so\n * `kit.legal.sections.privacy.rights.lead` is grouped under `legal` with the app's own\n * legal texts instead of under `kit.legal`:\n *\n * const namespaceOf = (key: string) => reviewAreaOf(key, [\"legal\"]) ?? ownNamespaceOf(key);\n *\n * Where two areas both hold the key (`legal` and `legal.privacy`), the longer — the more\n * specific — wins, whatever their order. `inArea` is the app's own rule, as for\n * {@link keyInAreas}.\n */\nexport function reviewAreaOf(\n key: string,\n areas: readonly string[],\n inArea: (key: string, area: string) => boolean = keyInArea,\n): string | undefined {\n let found: string | undefined;\n for (const area of areas) {\n if (inArea(key, area) && (found === undefined || area.length > found.length)) found = area;\n }\n return found;\n}\n\n/**\n * Whether `key` lies in one of `areas` — the scope a reviewer may be limited to\n * (keksdose: `[\"legal\"]`, a lawyer who judges the Imprint, the Privacy Policy and the\n * Terms and sees nothing else). `null`/`undefined` is every area. The server applies the\n * same rule and refuses verdicts outside; this decides only what is listed.\n */\nexport function keyInAreas(\n key: string,\n areas: readonly string[] | null | undefined,\n inArea: (key: string, area: string) => boolean = keyInArea,\n): boolean {\n return !areas || areas.some((area) => inArea(key, area));\n}\n\nexport interface TranslationRowsInput {\n locale: string;\n /** The locale's strings, `key → text` ({@link flattenStrings}). */\n strings: Readonly<Record<string, string>>;\n /** The reference locale's strings — whichever locale THIS app reads `locale` against. */\n reference: Readonly<Record<string, string>>;\n /** The verdicts: this locale's by key, or the whole list as the server sent it (other\n * locales' verdicts are skipped). */\n reviews?: ReadonlyMap<string, TranslationReview> | readonly TranslationReview[];\n /** Default {@link keyNamespace}. */\n namespaceOf?: (key: string) => string;\n /** The row's source, an app-defined word (kastlan: `doc_text.` keys are `documents`,\n * the rest `screen`). Default: none (`\"\"`). */\n sourceOf?: (key: string) => string;\n /** Keep only keys inside these areas ({@link keyInAreas}); `null` keeps every key. */\n areas?: readonly string[] | null;\n /** Default {@link keyInArea}. */\n inArea?: (key: string, area: string) => boolean;\n}\n\n/**\n * Every key of one locale, with its status: the reference's keys first, in its order, so\n * rows read the way the app's authors wrote them; a key only this locale has is appended\n * rather than dropped (a parity test should forbid it, but the page should not lie if one\n * slips through).\n */\nexport function translationRows({\n locale,\n strings,\n reference,\n reviews,\n namespaceOf: groupOf = keyNamespace,\n sourceOf,\n areas,\n inArea,\n}: TranslationRowsInput): TranslationRow[] {\n const byKey = new Map<string, TranslationReview>();\n if (reviews instanceof Map) {\n for (const [key, review] of reviews) byKey.set(key, review);\n } else if (reviews) {\n for (const review of reviews as readonly TranslationReview[]) {\n if (review.locale === locale) byKey.set(review.key, review);\n }\n }\n const keys = Object.keys(reference);\n for (const key of Object.keys(strings)) if (!(key in reference)) keys.push(key);\n return keys\n .filter((key) => keyInAreas(key, areas, inArea))\n .map((key) => {\n const text = strings[key] ?? \"\";\n const ref = reference[key] ?? \"\";\n const review = byKey.get(key) ?? null;\n return {\n id: `${locale}|${key}`,\n key,\n namespace: groupOf(key),\n source: sourceOf?.(key) ?? \"\",\n locale,\n text,\n reference: ref,\n status: reviewStatus(review, text, ref),\n review,\n placeholderMismatch: text !== \"\" && placeholderMismatch(text, ref),\n };\n });\n}\n\n/** How many rows stand where, and how many there are. */\nexport type TranslationSummary = Record<ReviewStatus, number> & { total: number };\n\nexport function summariseRows(rows: readonly TranslationRow[]): TranslationSummary {\n const summary: TranslationSummary = {\n missing: 0,\n unreviewed: 0,\n changed: 0,\n needs_change: 0,\n approved: 0,\n total: rows.length,\n };\n for (const row of rows) summary[row.status] += 1;\n return summary;\n}\n\n// ── Filtering ───────────────────────────────────────────────────────────────────\n\n/** The panel's filters. `\"all\"` switches one off. */\nexport interface TranslationReviewFilter {\n status: ReviewStatus | \"all\";\n source: string;\n namespace: string;\n /** Searched in the key, the text and the reference, folded as every kit list's search\n * is (`foldForSearch`): no case, no accents — \"uberweisung\" finds \"Überweisung\". */\n query: string;\n placeholdersOnly: boolean;\n}\n\nexport const DEFAULT_TRANSLATION_REVIEW_FILTER: TranslationReviewFilter = {\n status: \"all\",\n source: \"all\",\n namespace: \"all\",\n query: \"\",\n placeholdersOnly: false,\n};\n\nexport function filterTranslationRows(\n rows: readonly TranslationRow[],\n filter: Partial<TranslationReviewFilter>,\n): TranslationRow[] {\n const f = { ...DEFAULT_TRANSLATION_REVIEW_FILTER, ...filter };\n // Folded as every kit list's search is (DUP-5, refactor audit 2026-10).\n const q = foldForSearch(f.query.trim());\n return rows.filter(\n (row) =>\n (f.status === \"all\" || row.status === f.status) &&\n (f.source === \"all\" || row.source === f.source) &&\n (f.namespace === \"all\" || row.namespace === f.namespace) &&\n (!f.placeholdersOnly || row.placeholderMismatch) &&\n (!q || [row.key, row.text, row.reference].some((s) => foldForSearch(s).includes(q))),\n );\n}\n\n// ── Grouping ────────────────────────────────────────────────────────────────────\n\n/** One group of rows — an area, a source — and how they stand. */\nexport interface TranslationRowGroup {\n key: string;\n rows: TranslationRow[];\n summary: TranslationSummary;\n}\n\n/**\n * Rows in groups, each group where its first row is — the reference's order, so the areas\n * read the way the app's authors wrote the bundle — and each group's rows in their own\n * order. keksdose live #377: a reviewer on a phone works area by area (\"the budget\n * strings, then the legal ones\"), and a flat list of 3859 rows is not a way to see\n * where an area stands.\n *\n * `groupOf` names a row's group: `(row) => row.namespace` for the areas,\n * `(row) => row.source` for kastlan's screen texts and documents.\n */\nexport function groupTranslationRows(\n rows: readonly TranslationRow[],\n groupOf: (row: TranslationRow) => string,\n): TranslationRowGroup[] {\n const byKey = new Map<string, TranslationRow[]>();\n for (const row of rows) {\n const key = groupOf(row);\n const list = byKey.get(key);\n if (list) list.push(row);\n else byKey.set(key, [row]);\n }\n return [...byKey].map(([key, list]) => ({ key, rows: list, summary: summariseRows(list) }));\n}\n\n/**\n * The rows a group's \"Approve the unreviewed\" takes: the ones nobody has given a verdict\n * and that have a text. Not `changed` — a string that moved since it was judged asks to\n * be READ again, which a bulk action is the opposite of — and not `missing`, which has\n * nothing to approve.\n */\nexport function unreviewedRows(rows: readonly TranslationRow[]): TranslationRow[] {\n return rows.filter((row) => row.status === \"unreviewed\" && row.text !== \"\");\n}\n\n// ── Writing ─────────────────────────────────────────────────────────────────────\n\n/** What gets stored for a verdict: the wording it was given on, so a later change of the\n * string (or of its reference) shows up as `changed`. */\nexport function reviewWrite(\n row: TranslationRow,\n verdict: TranslationVerdict,\n note: string | null = null,\n suggestion: string | null = null,\n): TranslationReviewWrite {\n return {\n locale: row.locale,\n key: row.key,\n text: row.text,\n referenceText: row.reference,\n verdict,\n note,\n suggestion,\n };\n}\n\n/** What takes a set of verdicts back: see {@link reviewUndo}. */\nexport interface TranslationReviewUndo {\n /** The verdicts the rows had before, to store again — each on the wording it was\n * given on, so a row that was `changed` reads `changed` again. */\n writes: TranslationReviewWrite[];\n /** The rows that had no verdict before: back to unreviewed. */\n clears: TranslationReviewKey[];\n}\n\n/**\n * How to take back what was just said about `rows` — the rows AS THEY WERE before the\n * write, with the verdicts they carried then. The panel's Undo toast (0.25, keksdose live\n * #377) runs it: a swipe on a phone approves in one movement, and a movement can be a\n * mistake.\n *\n * A row that had a verdict gets it stored again (its note, its suggestion, the wording it\n * was judged on); one that had none is cleared. The server stamps the restored verdict\n * with the person undoing and the time, as it stamps every write — the contract has no\n * way to write a verdict in somebody else's name, and should not.\n */\nexport function reviewUndo(rows: readonly TranslationRow[]): TranslationReviewUndo {\n const writes: TranslationReviewWrite[] = [];\n const clears: TranslationReviewKey[] = [];\n for (const row of rows) {\n const before = row.review;\n if (!before) {\n clears.push({ locale: row.locale, key: row.key });\n continue;\n }\n writes.push({\n locale: row.locale,\n key: row.key,\n text: before.text,\n referenceText: before.referenceText,\n verdict: before.verdict,\n note: before.note,\n suggestion: before.suggestion,\n });\n }\n return { writes, clears };\n}\n\n/** The app's cached verdict list with `written` in place of what was said before — a\n * save answers with the rows it wrote, so a page patches its copy instead of\n * downloading every verdict again after each click. Any spelling with `locale` and\n * `key` (the API's or the kit's). */\nexport function mergeReviews<T extends TranslationReviewKey>(prev: readonly T[], written: readonly T[]): T[] {\n const id = (r: TranslationReviewKey) => `${r.locale}|${r.key}`;\n const replaced = new Set(written.map(id));\n return [...prev.filter((r) => !replaced.has(id(r))), ...written];\n}\n\n/** The cached list without the verdicts on `cleared`. */\nexport function dropReviews<T extends TranslationReviewKey>(\n prev: readonly T[],\n cleared: readonly TranslationReviewKey[],\n): T[] {\n const gone = new Set(cleared.map((r) => `${r.locale}|${r.key}`));\n return prev.filter((r) => !gone.has(`${r.locale}|${r.key}`));\n}\n\n// ── Swipe bindings ──────────────────────────────────────────────────────────────\n\n/**\n * What a phone card's swipe can be bound to in `TranslationReviewPanel`'s `swipe`\n * (keksdose — Marcel's live #377 rework, 2026-10-03: *\"Add the swipe options to be shown\n * also to the settings /settings#interaction area where the other swipe options are\n * defined\"*). keksdose lets the user bind every list's swipes there — per side, a primary\n * action at the first threshold and a secondary one at a longer drag — and lists each\n * surface's ids in its `SWIPE_ACTIONS`; this is the translation list's, in the order a\n * settings page offers them.\n *\n * - `approve` — the string is right as it stands. With the panel's Undo toast.\n * - `edit` — open the editor with the cursor in the wording: \"Needs a change\" (or\n * \"Suggest translation\" on a missing string). Writes nothing; the editor does.\n * - `clear` — take the verdict back: unreviewed again. With the Undo toast, which stores\n * the verdict again.\n *\n * THERE IS NO SEPARATE \"needs a change\". The editor has no verdict to preselect: Approve\n * and \"Needs a change\" stand side by side in it, and \"Needs a change\" takes a note or a\n * different wording — a verdict without either tells whoever fixes the string nothing, so\n * a swipe never sends one blind (0.25). The one honest thing a \"needs a change\" swipe can\n * do is therefore open the editor with the cursor in the wording — which is `edit`, and\n * `edit` already says \"Needs a change\" on the card. A second id doing the same would arm\n * a second threshold that does what the first already did: the duplicate keksdose's\n * `resolveSwipePlan` drops for exactly that reason.\n */\nexport const TRANSLATION_REVIEW_SWIPE_ACTIONS = [\"approve\", \"edit\", \"clear\"] as const;\n\n/** One of {@link TRANSLATION_REVIEW_SWIPE_ACTIONS}. */\nexport type TranslationReviewSwipeAction = (typeof TRANSLATION_REVIEW_SWIPE_ACTIONS)[number];\n\n/**\n * Which swipe does what on a phone card — `TranslationReviewPanel`'s `swipe`. Each side is\n * an ordered ladder, exactly as `SwipeableRow` and DataTable's `mobileSwipeActions` model\n * one: index 0 commits at the first threshold, index 1 at the longer drag (and so on — the\n * thresholds spread evenly over the card's width). A side left out, or empty, does not\n * swipe.\n *\n * LOGICAL SIDES: `end` is a drag toward the reading end of the line — right in a\n * left-to-right page, left in a right-to-left one — and `start` the other way, so one\n * binding holds in both directions. An app whose settings store physical sides (keksdose's\n * `right`/`left`) hands `right` as `end` for a left-to-right page.\n */\nexport interface TranslationReviewSwipeBinding {\n /** A drag toward the reading START, nearest threshold first. */\n start?: readonly TranslationReviewSwipeAction[];\n /** A drag toward the reading END, nearest threshold first. */\n end?: readonly TranslationReviewSwipeAction[];\n}\n\n/** What `swipe={true}` means — 0.25's fixed mapping: approve toward the end, open the\n * editor (\"Needs a change\") toward the start. A settings page's \"reset\" goes back here. */\nexport const DEFAULT_TRANSLATION_REVIEW_SWIPE: TranslationReviewSwipeBinding = Object.freeze({\n start: Object.freeze([\"edit\"] as const),\n end: Object.freeze([\"approve\"] as const),\n});\n\n/** The ladders one row actually offers, from a {@link TranslationReviewSwipeBinding}. */\nexport interface TranslationReviewSwipePlan {\n start: TranslationReviewSwipeAction[];\n end: TranslationReviewSwipeAction[];\n}\n\n/**\n * The binding resolved against one row — keksdose's `resolveSwipePlan`, for this list.\n * An id the row cannot offer DROPS OUT and the ladder closes up behind it, so the second\n * stage becomes the first rather than the side going dead behind an unreachable first\n * stage (or arming a threshold that does nothing):\n *\n * - `approve`: not on a missing string (nothing to approve) or an approved one (it would\n * say it again) — the rows that have no approve button either;\n * - `clear`: not without `canClear` (the app passed no `onClear`), and not on a row with\n * no verdict to take back (unreviewed; missing with no suggestion);\n * - `edit`: on every row;\n * - an id named twice on one side: the second time (a longer drag to the same effect);\n * - an id this version does not know (a binding stored by another version, an app's own\n * \"none\" slot): dropped like one that does not apply.\n *\n * Only what the ROW decides. Whether the panel may write at all — `readOnly`, no\n * `onSave`, a write lock, the row's own write still out — is the panel's, and then no\n * side swipes.\n */\nexport function translationReviewSwipePlan(\n binding: TranslationReviewSwipeBinding,\n row: TranslationRow,\n { canClear = false }: { canClear?: boolean } = {},\n): TranslationReviewSwipePlan {\n const offers = (id: TranslationReviewSwipeAction): boolean => {\n switch (id) {\n case \"approve\":\n return row.text !== \"\" && row.status !== \"approved\";\n case \"edit\":\n return true;\n case \"clear\":\n return canClear && row.review !== null;\n default:\n return false;\n }\n };\n const side = (ids: readonly TranslationReviewSwipeAction[] | undefined): TranslationReviewSwipeAction[] => {\n const out: TranslationReviewSwipeAction[] = [];\n for (const id of ids ?? []) {\n if (!out.includes(id) && offers(id)) out.push(id);\n }\n return out;\n };\n return { start: side(binding.start), end: side(binding.end) };\n}\n\n// ── Export ──────────────────────────────────────────────────────────────────────\n\n/**\n * One entry of the \"Export corrections\" file — enough for a developer to apply the change\n * to the bundle without opening the page. snake_case `reviewed_at` on purpose: this is a\n * FILE, the one keksdose and kastlan already write, beside an API spelled that way.\n */\nexport interface TranslationCorrection {\n locale: string;\n key: string;\n status: ReviewStatus;\n current: string;\n reference: string;\n suggestion: string | null;\n note: string | null;\n reviewer: string | null;\n reviewed_at: string | null;\n}\n\n/** The rows sent back (verdict NEEDS_CHANGE — a suggested translation for a missing\n * string included), as the export file lists them. */\nexport function translationCorrections(rows: readonly TranslationRow[]): TranslationCorrection[] {\n return rows\n .filter((row) => row.review?.verdict === \"NEEDS_CHANGE\")\n .map((row) => ({\n locale: row.locale,\n key: row.key,\n status: row.status,\n current: row.text,\n reference: row.reference,\n suggestion: row.review?.suggestion ?? null,\n note: row.review?.note ?? null,\n reviewer: row.review?.reviewerName ?? null,\n reviewed_at: row.review?.reviewedAt ?? null,\n }));\n}\n"],"mappings":";AAwBA,SAAS,qBAAqB;AAkDvB,MAAM,kBAA2C;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAkEO,SAAS,cAAc,QAAiD;AAC7E,SAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,KAAK,OAAO;AAAA,IACZ,MAAM,OAAO;AAAA,IACb,eAAe,OAAO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AAC5B,QAAM,SAAS,CAAC,OAA8C;AAC5D,YAAQ,IAAI;AAAA,MACV,KAAK;AACH,eAAO,IAAI,SAAS,MAAM,IAAI,WAAW;AAAA,MAC3C,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO,YAAY,IAAI,WAAW;AAAA,MACpC;AACE,eAAO;AAAA,IACX;AAAA,EACF;AACA,QAAM,OAAO,CAAC,QAA6F;AACzG,UAAM,MAAsC,CAAC;AAC7C,eAAW,MAAM,OAAO,CAAC,GAAG;AAC1B,UAAI,CAAC,IAAI,SAAS,EAAE,KAAK,OAAO,EAAE,EAAG,KAAI,KAAK,EAAE;AAAA,IAClD;AACA,WAAO;AAAA,EACT;AACA,SAAO,EAAE,OAAO,KAAK,QAAQ,KAAK,GAAG,KAAK,KAAK,QAAQ,GAAG,EAAE;AAC9D;AAuBO,SAAS,uBAAuB,MAA0D;AAC/F,SAAO,KACJ,OAAO,CAAC,QAAQ,IAAI,QAAQ,YAAY,cAAc,EACtD,IAAI,CAAC,SAAS;AAAA,IACb,QAAQ,IAAI;AAAA,IACZ,KAAK,IAAI;AAAA,IACT,QAAQ,IAAI;AAAA,IACZ,SAAS,IAAI;AAAA,IACb,WAAW,IAAI;AAAA,IACf,YAAY,IAAI,QAAQ,cAAc;AAAA,IACtC,MAAM,IAAI,QAAQ,QAAQ;AAAA,IAC1B,UAAU,IAAI,QAAQ,gBAAgB;AAAA,IACtC,aAAa,IAAI,QAAQ,cAAc;AAAA,EACzC,EAAE;AACN;","names":[]}
|
package/dist/pay/pay.js
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
3
|
// <define:__PAY_STRINGS__>
|
|
4
|
-
var define_PAY_STRINGS_default = { "de-CH": { opening: "Der sichere Bezahlvorgang wird ge\xF6ffnet\u2026", nothing: "Hier ist nichts zu bezahlen. Um einen Tarif zu w\xE4hlen, kehren Sie zur App zur\xFCck.", failed: "Der Bezahlvorgang konnte nicht ge\xF6ffnet werden. Bitte kehren Sie zur\xFCck und versuchen Sie es gleich noch einmal.", closed: "Der Bezahlvorgang wurde geschlossen. Sie k\xF6nnen zur\xFCckkehren oder diese Seite neu laden, um ihn wieder zu \xF6ffnen.", back: "Zur\xFCck", terms: "Nutzungsbedingungen", privacy: "Datenschutz", legal: "Rechtliches" }, en: { opening: "Opening the secure checkout\u2026", nothing: "There\u2019s no payment to make here. To choose a plan, go back to the app.", failed: "The checkout couldn\u2019t be opened. Please go back and try again in a moment.", closed: "The checkout was closed. You can go back, or reload this page to open it again.", back: "Back", terms: "Terms", privacy: "Privacy Policy", legal: "Legal" }, es: { opening: "Abriendo el pago seguro\u2026", nothing: "Aqu\xED no hay nada que pagar. Para elegir un plan, vuelva a la aplicaci\xF3n.", failed: "No se ha podido abrir el pago. Vuelva atr\xE1s e int\xE9ntelo de nuevo en un momento.", closed: "El pago se ha cerrado. Puede volver atr\xE1s o recargar esta p\xE1gina para abrirlo de nuevo.", back: "Atr\xE1s", terms: "Condiciones de uso", privacy: "Pol\xEDtica de privacidad", legal: "Informaci\xF3n legal" }, fr: { opening: "Ouverture du paiement s\xE9curis\xE9\u2026", nothing: "Il n\u2019y a rien \xE0 payer ici. Pour choisir une formule, revenez \xE0 l\u2019application.", failed: "Le paiement n\u2019a pas pu s\u2019ouvrir. Veuillez revenir en arri\xE8re et r\xE9essayer dans un instant.", closed: "Le paiement a \xE9t\xE9 ferm\xE9. Vous pouvez revenir en arri\xE8re, ou recharger cette page pour le rouvrir.", back: "Retour", terms: "Conditions d\u2019utilisation", privacy: "Confidentialit\xE9", legal: "Informations l\xE9gales" }, it: { opening: "Apertura del pagamento sicuro\u2026", nothing: "Qui non c\u2019\xE8 nulla da pagare. Per scegliere un piano, torni all\u2019app.", failed: "Non \xE8 stato possibile aprire il pagamento. Torni indietro e riprovi tra un momento.", closed: "Il pagamento \xE8 stato chiuso. Pu\xF2 tornare indietro, oppure ricaricare questa pagina per riaprirlo.", back: "Indietro", terms: "Condizioni d\u2019uso", privacy: "Privacy", legal: "Note legali" }, hu: { opening: "A biztons\xE1gos fizet\xE9s megnyit\xE1sa\u2026", nothing: "Itt nincs mit kifizetni. Csomag v\xE1laszt\xE1s\xE1hoz t\xE9rjen vissza az alkalmaz\xE1sba.", failed: "A fizet\xE9st nem siker\xFClt megnyitni. K\xE9rj\xFCk, l\xE9pjen vissza, \xE9s pr\xF3b\xE1lja \xFAjra egy kis id\u0151 m\xFAlva.", closed: "A fizet\xE9s bez\xE1rult. Visszal\xE9phet, vagy a megnyit\xE1s\xE1hoz t\xF6ltse \xFAjra ezt az oldalt.", back: "Vissza", terms: "Felhaszn\xE1l\xE1si felt\xE9telek", privacy: "Adatv\xE9delmi t\xE1j\xE9koztat\xF3", legal: "Jogi inform\xE1ci\xF3k" }, zh: { opening: "\u6B63\u5728\u6253\u5F00\u5B89\u5168\u652F\u4ED8\u9875\u9762\u2026", nothing: "\u8FD9\u91CC\u6CA1\u6709\u9700\u8981\u652F\u4ED8\u7684\u6B3E\u9879\u3002\u5982\u9700\u9009\u62E9\u5957\u9910\uFF0C\u8BF7\u8FD4\u56DE\u5E94\u7528\u3002", failed: "\u65E0\u6CD5\u6253\u5F00\u652F\u4ED8\u9875\u9762\u3002\u8BF7\u8FD4\u56DE\u540E\u7A0D\u5019\u518D\u8BD5\u3002", closed: "\u652F\u4ED8\u9875\u9762\u5DF2\u5173\u95ED\u3002\u60A8\u53EF\u4EE5\u8FD4\u56DE\uFF0C\u6216\u91CD\u65B0\u52A0\u8F7D\u6B64\u9875\u9762\u4EE5\u518D\u6B21\u6253\u5F00\u3002", back: "\u4E0A\u4E00\u6B65", terms: "\u4F7F\u7528\u6761\u6B3E", privacy: "\u9690\u79C1\u653F\u7B56", legal: "\u6CD5\u5F8B\u4FE1\u606F" } };
|
|
5
|
-
|
|
6
|
-
// src/billing/checkout-return.ts
|
|
7
|
-
var CHECKOUT_RETURN_PARAM = "checkout";
|
|
8
|
-
var CHECKOUT_RETURN_VALUE = "done";
|
|
9
|
-
function checkoutReturnUrl(page) {
|
|
10
|
-
const hashAt = page.indexOf("#");
|
|
11
|
-
const hash = hashAt === -1 ? "" : page.slice(hashAt);
|
|
12
|
-
const beforeHash = hashAt === -1 ? page : page.slice(0, hashAt);
|
|
13
|
-
const queryAt = beforeHash.indexOf("?");
|
|
14
|
-
const path = queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt);
|
|
15
|
-
const kept = (queryAt === -1 ? "" : beforeHash.slice(queryAt + 1)).split("&").filter((part) => part !== "" && decodeKey(part) !== CHECKOUT_RETURN_PARAM);
|
|
16
|
-
kept.push(`${CHECKOUT_RETURN_PARAM}=${CHECKOUT_RETURN_VALUE}`);
|
|
17
|
-
return `${path}?${kept.join("&")}${hash}`;
|
|
18
|
-
}
|
|
19
|
-
function decodeKey(part) {
|
|
20
|
-
const key = part.split("=")[0].replace(/\+/g, " ");
|
|
21
|
-
try {
|
|
22
|
-
return decodeURIComponent(key);
|
|
23
|
-
} catch {
|
|
24
|
-
return key;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
4
|
+
var define_PAY_STRINGS_default = { "de-CH": { opening: "Der sichere Bezahlvorgang wird ge\xF6ffnet\u2026", nothing: "Hier ist nichts zu bezahlen. Um einen Tarif zu w\xE4hlen, kehren Sie zur App zur\xFCck.", failed: "Der Bezahlvorgang konnte nicht ge\xF6ffnet werden. Bitte kehren Sie zur\xFCck und versuchen Sie es gleich noch einmal.", closed: "Der Bezahlvorgang wurde geschlossen. Sie k\xF6nnen zur\xFCckkehren oder diese Seite neu laden, um ihn wieder zu \xF6ffnen.", done: "Zahlung abgeschlossen. Sie k\xF6nnen diese Seite schliessen.", back: "Zur\xFCck", terms: "Nutzungsbedingungen", privacy: "Datenschutz", legal: "Rechtliches" }, en: { opening: "Opening the secure checkout\u2026", nothing: "There\u2019s no payment to make here. To choose a plan, go back to the app.", failed: "The checkout couldn\u2019t be opened. Please go back and try again in a moment.", closed: "The checkout was closed. You can go back, or reload this page to open it again.", done: "Payment complete. You can close this page.", back: "Back", terms: "Terms", privacy: "Privacy Policy", legal: "Legal" }, es: { opening: "Abriendo el pago seguro\u2026", nothing: "Aqu\xED no hay nada que pagar. Para elegir un plan, vuelva a la aplicaci\xF3n.", failed: "No se ha podido abrir el pago. Vuelva atr\xE1s e int\xE9ntelo de nuevo en un momento.", closed: "El pago se ha cerrado. Puede volver atr\xE1s o recargar esta p\xE1gina para abrirlo de nuevo.", done: "Pago completado. Puede cerrar esta p\xE1gina.", back: "Atr\xE1s", terms: "Condiciones de uso", privacy: "Pol\xEDtica de privacidad", legal: "Informaci\xF3n legal" }, fr: { opening: "Ouverture du paiement s\xE9curis\xE9\u2026", nothing: "Il n\u2019y a rien \xE0 payer ici. Pour choisir une formule, revenez \xE0 l\u2019application.", failed: "Le paiement n\u2019a pas pu s\u2019ouvrir. Veuillez revenir en arri\xE8re et r\xE9essayer dans un instant.", closed: "Le paiement a \xE9t\xE9 ferm\xE9. Vous pouvez revenir en arri\xE8re, ou recharger cette page pour le rouvrir.", done: "Paiement effectu\xE9. Vous pouvez fermer cette page.", back: "Retour", terms: "Conditions d\u2019utilisation", privacy: "Confidentialit\xE9", legal: "Informations l\xE9gales" }, it: { opening: "Apertura del pagamento sicuro\u2026", nothing: "Qui non c\u2019\xE8 nulla da pagare. Per scegliere un piano, torni all\u2019app.", failed: "Non \xE8 stato possibile aprire il pagamento. Torni indietro e riprovi tra un momento.", closed: "Il pagamento \xE8 stato chiuso. Pu\xF2 tornare indietro, oppure ricaricare questa pagina per riaprirlo.", done: "Pagamento completato. Pu\xF2 chiudere questa pagina.", back: "Indietro", terms: "Condizioni d\u2019uso", privacy: "Privacy", legal: "Note legali" }, hu: { opening: "A biztons\xE1gos fizet\xE9s megnyit\xE1sa\u2026", nothing: "Itt nincs mit kifizetni. Csomag v\xE1laszt\xE1s\xE1hoz t\xE9rjen vissza az alkalmaz\xE1sba.", failed: "A fizet\xE9st nem siker\xFClt megnyitni. K\xE9rj\xFCk, l\xE9pjen vissza, \xE9s pr\xF3b\xE1lja \xFAjra egy kis id\u0151 m\xFAlva.", closed: "A fizet\xE9s bez\xE1rult. Visszal\xE9phet, vagy a megnyit\xE1s\xE1hoz t\xF6ltse \xFAjra ezt az oldalt.", done: "A fizet\xE9s siker\xFClt. Bez\xE1rhatja ezt az oldalt.", back: "Vissza", terms: "Felhaszn\xE1l\xE1si felt\xE9telek", privacy: "Adatv\xE9delmi t\xE1j\xE9koztat\xF3", legal: "Jogi inform\xE1ci\xF3k" }, zh: { opening: "\u6B63\u5728\u6253\u5F00\u5B89\u5168\u652F\u4ED8\u9875\u9762\u2026", nothing: "\u8FD9\u91CC\u6CA1\u6709\u9700\u8981\u652F\u4ED8\u7684\u6B3E\u9879\u3002\u5982\u9700\u9009\u62E9\u5957\u9910\uFF0C\u8BF7\u8FD4\u56DE\u5E94\u7528\u3002", failed: "\u65E0\u6CD5\u6253\u5F00\u652F\u4ED8\u9875\u9762\u3002\u8BF7\u8FD4\u56DE\u540E\u7A0D\u5019\u518D\u8BD5\u3002", closed: "\u652F\u4ED8\u9875\u9762\u5DF2\u5173\u95ED\u3002\u60A8\u53EF\u4EE5\u8FD4\u56DE\uFF0C\u6216\u91CD\u65B0\u52A0\u8F7D\u6B64\u9875\u9762\u4EE5\u518D\u6B21\u6253\u5F00\u3002", done: "\u4ED8\u6B3E\u5DF2\u5B8C\u6210\u3002\u60A8\u53EF\u4EE5\u5173\u95ED\u6B64\u9875\u9762\u3002", back: "\u4E0A\u4E00\u6B65", terms: "\u4F7F\u7528\u6761\u6B3E", privacy: "\u9690\u79C1\u653F\u7B56", legal: "\u6CD5\u5F8B\u4FE1\u606F" } };
|
|
27
5
|
|
|
28
6
|
// src/billing/pay-page.ts
|
|
29
7
|
var PAY_PAGE_LANG_PARAM = "lang";
|
|
@@ -59,8 +37,17 @@
|
|
|
59
37
|
return "en";
|
|
60
38
|
}
|
|
61
39
|
var PAY_CONFIG_FILE = "pay-config.json";
|
|
40
|
+
var APP_TAG = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
41
|
+
function appAt(name, site, returnPath) {
|
|
42
|
+
return { name, returnUrl: `${site}${returnPath}`, termsUrl: `${site}/terms`, privacyUrl: `${site}/privacy` };
|
|
43
|
+
}
|
|
44
|
+
var PAY_PAGE_APPS = Object.freeze({
|
|
45
|
+
keksdose: Object.freeze(appAt("Keksdose", "https://keksdose.app", "/settings/subscription")),
|
|
46
|
+
kastlan: Object.freeze(appAt("Kastlan", "https://kastlan.app", "/admin/billing")),
|
|
47
|
+
kurvenschmiede: Object.freeze(appAt("Kurvenschmiede", "https://kurvenschmiede.app", "/settings/subscription"))
|
|
48
|
+
});
|
|
62
49
|
var TOKEN_PREFIX = { sandbox: "test_", live: "live_" };
|
|
63
|
-
function
|
|
50
|
+
function isPayPageUrl(value) {
|
|
64
51
|
if (typeof value !== "string") return false;
|
|
65
52
|
let url;
|
|
66
53
|
try {
|
|
@@ -71,6 +58,22 @@
|
|
|
71
58
|
if (url.protocol === "https:") return true;
|
|
72
59
|
return url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
73
60
|
}
|
|
61
|
+
function hasApp(apps, tag) {
|
|
62
|
+
return typeof tag === "string" && APP_TAG.test(tag) && typeof apps === "object" && apps !== null && Object.prototype.hasOwnProperty.call(apps, tag);
|
|
63
|
+
}
|
|
64
|
+
function payPageAppFor(config, tag) {
|
|
65
|
+
return hasApp(config.apps, tag) ? config.apps[tag] : void 0;
|
|
66
|
+
}
|
|
67
|
+
function appProblems(tag, app) {
|
|
68
|
+
if (typeof app !== "object" || app === null) return [`apps.${tag} is not an object`];
|
|
69
|
+
const a = app;
|
|
70
|
+
const problems = [];
|
|
71
|
+
if (typeof a.name !== "string" || a.name.trim() === "") problems.push(`apps.${tag}.name is missing`);
|
|
72
|
+
for (const key of ["returnUrl", "termsUrl", "privacyUrl"]) {
|
|
73
|
+
if (!isPayPageUrl(a[key])) problems.push(`apps.${tag}.${key} must be an https:// URL (http:// for localhost only)`);
|
|
74
|
+
}
|
|
75
|
+
return problems;
|
|
76
|
+
}
|
|
74
77
|
function payPageConfigProblems(config) {
|
|
75
78
|
if (typeof config !== "object" || config === null) return ["the configuration is not an object"];
|
|
76
79
|
const c = config;
|
|
@@ -91,14 +94,43 @@
|
|
|
91
94
|
);
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
const { apps, app } = c;
|
|
98
|
+
if (typeof apps !== "object" || apps === null || Array.isArray(apps) || Object.keys(apps).length === 0) {
|
|
99
|
+
problems.push("apps must map each app's tag to its name and URLs");
|
|
100
|
+
} else {
|
|
101
|
+
for (const [tag, entry] of Object.entries(apps)) {
|
|
102
|
+
if (!APP_TAG.test(tag)) problems.push(`apps: ${JSON.stringify(tag)} is not an app tag (a-z, 0-9, _ and -)`);
|
|
103
|
+
else problems.push(...appProblems(tag, entry));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (typeof app !== "string" || app === "") problems.push("app is missing: the host's own app tag");
|
|
107
|
+
else if (!hasApp(apps, app)) {
|
|
108
|
+
const known = typeof apps === "object" && apps !== null ? Object.keys(apps).join(", ") : "";
|
|
109
|
+
problems.push(`app ${JSON.stringify(app)} is not in apps${known ? ` (${known})` : ""}`);
|
|
96
110
|
}
|
|
97
|
-
if (typeof c.appName !== "string" || c.appName.trim() === "") problems.push("appName is missing");
|
|
98
111
|
return problems;
|
|
99
112
|
}
|
|
100
|
-
|
|
101
|
-
|
|
113
|
+
|
|
114
|
+
// src/billing/checkout-return.ts
|
|
115
|
+
var CHECKOUT_RETURN_PARAM = "checkout";
|
|
116
|
+
var CHECKOUT_RETURN_VALUE = "done";
|
|
117
|
+
function checkoutReturnUrl(page) {
|
|
118
|
+
const hashAt = page.indexOf("#");
|
|
119
|
+
const hash = hashAt === -1 ? "" : page.slice(hashAt);
|
|
120
|
+
const beforeHash = hashAt === -1 ? page : page.slice(0, hashAt);
|
|
121
|
+
const queryAt = beforeHash.indexOf("?");
|
|
122
|
+
const path = queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt);
|
|
123
|
+
const kept = (queryAt === -1 ? "" : beforeHash.slice(queryAt + 1)).split("&").filter((part) => part !== "" && decodeKey(part) !== CHECKOUT_RETURN_PARAM);
|
|
124
|
+
kept.push(`${CHECKOUT_RETURN_PARAM}=${CHECKOUT_RETURN_VALUE}`);
|
|
125
|
+
return `${path}?${kept.join("&")}${hash}`;
|
|
126
|
+
}
|
|
127
|
+
function decodeKey(part) {
|
|
128
|
+
const key = part.split("=")[0].replace(/\+/g, " ");
|
|
129
|
+
try {
|
|
130
|
+
return decodeURIComponent(key);
|
|
131
|
+
} catch {
|
|
132
|
+
return key;
|
|
133
|
+
}
|
|
102
134
|
}
|
|
103
135
|
|
|
104
136
|
// pay-page/pay.ts
|
|
@@ -126,14 +158,22 @@
|
|
|
126
158
|
anchor.href = href;
|
|
127
159
|
anchor.hidden = false;
|
|
128
160
|
}
|
|
129
|
-
function frame(view, words,
|
|
130
|
-
link(view.back, words.back,
|
|
131
|
-
if (view.app) view.app.textContent =
|
|
161
|
+
function frame(view, words, app, doc) {
|
|
162
|
+
link(view.back, words.back, app.returnUrl);
|
|
163
|
+
if (view.app) view.app.textContent = app.name;
|
|
132
164
|
view.legal?.setAttribute("aria-label", words.legal);
|
|
133
|
-
link(view.terms, words.terms,
|
|
134
|
-
link(view.privacy, words.privacy,
|
|
165
|
+
link(view.terms, words.terms, app.termsUrl);
|
|
166
|
+
link(view.privacy, words.privacy, app.privacyUrl);
|
|
135
167
|
if (view.footer) view.footer.hidden = false;
|
|
136
|
-
doc.title =
|
|
168
|
+
doc.title = app.name;
|
|
169
|
+
}
|
|
170
|
+
function unframe(view, doc, title) {
|
|
171
|
+
if (view.back) {
|
|
172
|
+
view.back.hidden = true;
|
|
173
|
+
view.back.removeAttribute("href");
|
|
174
|
+
}
|
|
175
|
+
if (view.app) view.app.textContent = "";
|
|
176
|
+
doc.title = title;
|
|
137
177
|
}
|
|
138
178
|
async function startPayPage(env) {
|
|
139
179
|
const params = new URLSearchParams(env.search);
|
|
@@ -141,6 +181,7 @@
|
|
|
141
181
|
const words = env.strings[language] ?? env.strings.en;
|
|
142
182
|
const doc = env.document;
|
|
143
183
|
doc.documentElement.lang = language;
|
|
184
|
+
const untitled = doc.title;
|
|
144
185
|
const view = viewOf(doc);
|
|
145
186
|
show(view, words, "opening");
|
|
146
187
|
let raw;
|
|
@@ -153,24 +194,43 @@
|
|
|
153
194
|
return show(view, words, "failed");
|
|
154
195
|
}
|
|
155
196
|
const config = raw;
|
|
156
|
-
|
|
197
|
+
const host = config.apps[config.app];
|
|
198
|
+
frame(view, words, host, doc);
|
|
157
199
|
const transaction = params.get(PAY_PAGE_TRANSACTION_PARAM);
|
|
158
200
|
if (!config.token || !transaction) return show(view, words, "nothing");
|
|
159
201
|
const paddle = env.paddle();
|
|
160
202
|
if (!paddle) return show(view, words, "failed");
|
|
161
203
|
try {
|
|
162
204
|
if (config.environment === "sandbox") paddle.Environment.set("sandbox");
|
|
205
|
+
let app = host;
|
|
206
|
+
let paid = false;
|
|
207
|
+
const appOf = (event) => event.data && typeof event.data === "object" ? payPageAppFor(config, event.data.custom_data?.app) : app;
|
|
163
208
|
paddle.Initialize({
|
|
164
209
|
token: config.token,
|
|
165
210
|
eventCallback: (event) => {
|
|
166
|
-
if (
|
|
211
|
+
if (paid) return;
|
|
212
|
+
if (event?.name === "checkout.loaded") {
|
|
213
|
+
app = appOf(event);
|
|
214
|
+
if (app) frame(view, words, app, doc);
|
|
215
|
+
else unframe(view, doc, untitled);
|
|
216
|
+
} else if (event?.name === "checkout.completed") {
|
|
217
|
+
paid = true;
|
|
218
|
+
app = appOf(event);
|
|
219
|
+
if (app) env.navigate(checkoutReturnUrl(app.returnUrl));
|
|
220
|
+
else {
|
|
221
|
+
unframe(view, doc, untitled);
|
|
222
|
+
show(view, words, "done");
|
|
223
|
+
}
|
|
224
|
+
} else if (event?.name === "checkout.closed") {
|
|
225
|
+
show(view, words, "closed");
|
|
226
|
+
}
|
|
167
227
|
},
|
|
168
|
-
// Paddle.js opens the transaction `_ptxn` names with these settings by itself.
|
|
228
|
+
// Paddle.js opens the transaction `_ptxn` names with these settings by itself. No
|
|
229
|
+
// `successUrl`: the way back is the transaction's app's, known once it loads.
|
|
169
230
|
checkout: {
|
|
170
231
|
settings: {
|
|
171
232
|
displayMode: "overlay",
|
|
172
233
|
locale: paddleLocale(language),
|
|
173
|
-
successUrl: paySuccessUrl(config),
|
|
174
234
|
theme: env.dark ? "dark" : "light"
|
|
175
235
|
}
|
|
176
236
|
}
|
|
@@ -193,6 +253,8 @@
|
|
|
193
253
|
return response.json();
|
|
194
254
|
},
|
|
195
255
|
dark: window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? false,
|
|
196
|
-
strings: define_PAY_STRINGS_default
|
|
256
|
+
strings: define_PAY_STRINGS_default,
|
|
257
|
+
// Once paid, to the transaction's app — a URL from the configuration's map only.
|
|
258
|
+
navigate: (url) => window.location.assign(url)
|
|
197
259
|
});
|
|
198
260
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eifi1/ui-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "App-agnostic shared design system: domain-free React components, theme and tokens.",
|
|
6
6
|
"_sideEffects": "The barrel (src/index.ts) re-exports EVERY component, including components/chart, which statically imports recharts. Without this field a bundler must assume each of those modules has side effects, so it cannot drop the unused ones: importing a Button from '@eifi1/ui-kit' dragged all 433KB of recharts into the consumer's ENTRY chunk, and Keksdose was preloading it on every page load, login included. Nothing in src/ imports for side effects (no bare imports, no CSS imports from JS, no module-level global writes) — the token stylesheet is its own './tokens.css' export — so this is safe. CSS is still listed so any future stylesheet survives. Re-checked when `flag-icons` left `dependencies` and tsup started emitting a `\"use client\"` banner: neither touches this. The flag stylesheet was never imported from JS in the first place (that was the finding), and a directive prologue is a string literal every bundler lifts out before it decides whether a module is inert.",
|
package/src/auth/auth-errors.ts
CHANGED
|
@@ -115,9 +115,14 @@ export type DemoErrorCode =
|
|
|
115
115
|
* - `billing_not_at_provider` — `409`: a portal request before the payer reached the
|
|
116
116
|
* provider (§14.5) — a stale page; the overview's `at_provider` says it first.
|
|
117
117
|
* - `billing_already_subscribed` — `409`: a checkout while a provider subscription runs
|
|
118
|
-
* (§14.6).
|
|
118
|
+
* (§14.6). Since 0.39 plan changes go through the plan switch (§15.2.10).
|
|
119
119
|
* - `billing_plan_not_sold` — `422`: a checkout for a plan, currency or interval the
|
|
120
|
-
* catalogue doesn't sell.
|
|
120
|
+
* catalogue doesn't sell — or (0.39) a switch to one.
|
|
121
|
+
*
|
|
122
|
+
* 0.39.0 (server-kit 0.12, §15.2.10): the plan switch's refusals.
|
|
123
|
+
* - `billing_not_subscribed` — `409`: a switch with no running provider subscription;
|
|
124
|
+
* the page offers the checkout instead.
|
|
125
|
+
* - `billing_plan_unchanged` — `409`: a switch to the price the payer pays now.
|
|
121
126
|
*/
|
|
122
127
|
export type BillingErrorCode =
|
|
123
128
|
| "billing_disabled"
|
|
@@ -127,7 +132,9 @@ export type BillingErrorCode =
|
|
|
127
132
|
| "billing_provider_unavailable"
|
|
128
133
|
| "billing_not_at_provider"
|
|
129
134
|
| "billing_already_subscribed"
|
|
130
|
-
| "billing_plan_not_sold"
|
|
135
|
+
| "billing_plan_not_sold"
|
|
136
|
+
| "billing_not_subscribed"
|
|
137
|
+
| "billing_plan_unchanged";
|
|
131
138
|
|
|
132
139
|
/** Every code the kit reads: the sign-in refusals, the account ones (0.30.0), the demo's
|
|
133
140
|
* (0.31.0) and billing's (0.32.0). */
|
|
@@ -142,6 +149,8 @@ const BILLING_CODES: ReadonlySet<BillingErrorCode> = new Set<BillingErrorCode>([
|
|
|
142
149
|
"billing_not_at_provider",
|
|
143
150
|
"billing_already_subscribed",
|
|
144
151
|
"billing_plan_not_sold",
|
|
152
|
+
"billing_not_subscribed",
|
|
153
|
+
"billing_plan_unchanged",
|
|
145
154
|
]);
|
|
146
155
|
|
|
147
156
|
const CODES: ReadonlySet<string> = new Set<KitErrorCode>([
|
|
@@ -164,6 +164,25 @@ export interface BillingLabels {
|
|
|
164
164
|
payFailed: string;
|
|
165
165
|
/** The buyer closed the checkout without paying. */
|
|
166
166
|
payBack: string;
|
|
167
|
+
/** 0.39 (§15.2.5): paid, for a transaction that names no app the page knows (a
|
|
168
|
+
* payment-method update from Paddle's e-mail) — no way back to offer. */
|
|
169
|
+
payDone: string;
|
|
170
|
+
|
|
171
|
+
/* ── PlanSwitchConfirm (0.39, §15.2.10) ── */
|
|
172
|
+
/** The dialog's title: "Change plan". */
|
|
173
|
+
switchTitle: string;
|
|
174
|
+
/** The line naming both plans, each with its billing period: "From Pro (Monthly) to
|
|
175
|
+
* Business (Yearly)". */
|
|
176
|
+
switchFromTo: (from: string, to: string) => string;
|
|
177
|
+
/** What an upgrade charges at once (Paddle's preview, prorated): "Charged now". */
|
|
178
|
+
switchChargedNow: string;
|
|
179
|
+
/** What a downgrade credits — the customer's balance, which Paddle takes off the next
|
|
180
|
+
* charges: "Credited towards your next charges". */
|
|
181
|
+
switchCredited: string;
|
|
182
|
+
/** The next regular charge; `date` is formatted: "Next charge on 9 Nov 2026". */
|
|
183
|
+
switchNextCharge: (date: string) => string;
|
|
184
|
+
/** The confirm button: "Change plan". */
|
|
185
|
+
switchConfirm: string;
|
|
167
186
|
|
|
168
187
|
/* ── Offline (§12.5) ── */
|
|
169
188
|
/** Changes refused as `billing_read_only` inside a sync reply, kept queued and sent
|
|
@@ -189,11 +208,17 @@ export interface BillingLabels {
|
|
|
189
208
|
/** `billing_provider_unavailable` (502): the provider didn't answer. Try again. */
|
|
190
209
|
providerUnavailable: string;
|
|
191
210
|
/** `billing_already_subscribed` (409): a second checkout while a subscription runs
|
|
192
|
-
* (§14.6)
|
|
211
|
+
* (§14.6). Since 0.39 plan changes go through the app's own switch (§15.2.10), not the
|
|
212
|
+
* portal, and the words say so. */
|
|
193
213
|
alreadySubscribed: string;
|
|
194
214
|
/** `billing_plan_not_sold` (422): the catalogue doesn't sell this plan with that
|
|
195
|
-
* period or currency. */
|
|
215
|
+
* period or currency — at a checkout, or (0.39) a switch to a plan no longer sold. */
|
|
196
216
|
planNotSold: string;
|
|
217
|
+
/** 0.39 (§15.2.10): `billing_not_subscribed` (409), a plan switch with no running
|
|
218
|
+
* provider subscription — the page offers the checkout instead. */
|
|
219
|
+
notSubscribed: string;
|
|
220
|
+
/** 0.39: `billing_plan_unchanged` (409), a switch to the price the payer pays now. */
|
|
221
|
+
planUnchanged: string;
|
|
197
222
|
}
|
|
198
223
|
|
|
199
224
|
/** "today", "tomorrow", "in 5 days". */
|
|
@@ -266,6 +291,14 @@ export const DEFAULT_BILLING_LABELS: BillingLabels = {
|
|
|
266
291
|
payNothing: "There’s no payment to make here. To choose a plan, go back to the app.",
|
|
267
292
|
payFailed: "The checkout couldn’t be opened. Please go back and try again in a moment.",
|
|
268
293
|
payBack: "The checkout was closed. You can go back, or reload this page to open it again.",
|
|
294
|
+
payDone: "Payment complete. You can close this page.",
|
|
295
|
+
|
|
296
|
+
switchTitle: "Change plan",
|
|
297
|
+
switchFromTo: (from, to) => `From ${from} to ${to}`,
|
|
298
|
+
switchChargedNow: "Charged now",
|
|
299
|
+
switchCredited: "Credited towards your next charges",
|
|
300
|
+
switchNextCharge: (date) => `Next charge on ${date}`,
|
|
301
|
+
switchConfirm: "Change plan",
|
|
269
302
|
|
|
270
303
|
waitingChanges: (count) =>
|
|
271
304
|
count === 1 ? "1 change waiting for a plan" : `${count} changes waiting for a plan`,
|
|
@@ -274,8 +307,10 @@ export const DEFAULT_BILLING_LABELS: BillingLabels = {
|
|
|
274
307
|
notConfigured: "Payments aren't set up yet. Please try again later.",
|
|
275
308
|
disabled: "Subscriptions aren't available here.",
|
|
276
309
|
providerUnavailable: "The payment provider can’t be reached right now. Please try again in a moment.",
|
|
277
|
-
alreadySubscribed: "You already have a subscription.
|
|
310
|
+
alreadySubscribed: "You already have a subscription. Change your plan above.",
|
|
278
311
|
planNotSold: "This plan isn’t offered for that billing period or currency. Please choose another.",
|
|
312
|
+
notSubscribed: "There’s no running subscription to change. Choose a plan to subscribe.",
|
|
313
|
+
planUnchanged: "That’s already your plan. Pick another plan or billing period.",
|
|
279
314
|
};
|
|
280
315
|
|
|
281
316
|
/** The `billing` namespace, resolved: English, then the provider, then `labels` — which
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DateInput } from "../lib/format";
|
|
2
2
|
import type { SubscriptionStatus } from "./billing-labels";
|
|
3
|
-
import type { BillingCurrency } from "./plan-price";
|
|
3
|
+
import type { BillingCurrency, BillingInterval } from "./plan-price";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The billing API's shapes the kit's parts read (docs/billing-harmonization.md §4,
|
|
@@ -37,6 +37,58 @@ export interface BillingOverview {
|
|
|
37
37
|
* portal request would answer `409 billing_not_at_provider`.
|
|
38
38
|
*/
|
|
39
39
|
at_provider: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 0.39 (server-kit 0.12, §15.2.10): the price the payer pays at the provider — its
|
|
42
|
+
* plan, period and currency — or null with none (a trial, a grant without a purchase).
|
|
43
|
+
* Under a grant the row keeps the grant's plan, status and source (§12.11), so this
|
|
44
|
+
* is what shows that a switch landed; `checkoutFingerprint` reads it.
|
|
45
|
+
*/
|
|
46
|
+
paid: PaidPrice | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 0.39: what the payer pays at the provider (server-kit's `PaidPrice`, §15.2.10),
|
|
50
|
+
* read from the row's `provider_price_id`. */
|
|
51
|
+
export interface PaidPrice {
|
|
52
|
+
/** The plan's code, lowercase. */
|
|
53
|
+
plan: string;
|
|
54
|
+
interval: BillingInterval;
|
|
55
|
+
currency: BillingCurrency;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 0.39: `POST /billing/plan/preview` and `POST /billing/plan`'s body (server-kit's
|
|
59
|
+
* `PlanSwitchRequest`, §15.2.10) — the plan and period to switch to. The currency stays
|
|
60
|
+
* the subscription's. */
|
|
61
|
+
export interface PlanSwitchRequest {
|
|
62
|
+
plan: string;
|
|
63
|
+
interval: BillingInterval;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 0.39: what a plan switch costs — or did (server-kit's `PlanSwitchPreview`, §15.2.10):
|
|
68
|
+
* Paddle's preview, prorated at once, both routes' answer. `PlanSwitchConfirm` shows it
|
|
69
|
+
* before the payer agrees.
|
|
70
|
+
*/
|
|
71
|
+
export interface PlanSwitchPreview {
|
|
72
|
+
/** The subscription's currency. */
|
|
73
|
+
currency: BillingCurrency;
|
|
74
|
+
/** Charged at once, in minor units: an upgrade's prorated difference — or, negative, a
|
|
75
|
+
* downgrade's credit to the customer's balance, which Paddle takes off the next
|
|
76
|
+
* charges. */
|
|
77
|
+
now_minor: number;
|
|
78
|
+
/** The next regular charge, in minor units. */
|
|
79
|
+
next_minor?: number | null;
|
|
80
|
+
/** When it is charged; null when Paddle names no date. */
|
|
81
|
+
next_billed_at?: string | null;
|
|
82
|
+
/** The plan and period switched to. */
|
|
83
|
+
plan: string;
|
|
84
|
+
interval: BillingInterval;
|
|
85
|
+
/** The dimensions whose usage is over the new plan's limit (§3.4: a limit gates
|
|
86
|
+
* creation only — the switch is allowed). */
|
|
87
|
+
over_limit: string[];
|
|
88
|
+
/** The new plan's limits; null for unlimited. */
|
|
89
|
+
limits: Record<string, number | null>;
|
|
90
|
+
/** What the payer has, per dimension. */
|
|
91
|
+
usage: Record<string, number>;
|
|
40
92
|
}
|
|
41
93
|
|
|
42
94
|
/**
|