@puzzle-ui/i18n 0.0.0-stage → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +91 -2
  2. package/ai/instructions.md +141 -0
  3. package/ai/manifest.json +10 -0
  4. package/dist/LICENSE +21 -0
  5. package/dist/_virtual/_rolldown/runtime.cjs +22 -0
  6. package/dist/adapters/next.cjs +11 -0
  7. package/dist/adapters/next.cjs.map +1 -0
  8. package/dist/adapters/next.d.cts +7 -0
  9. package/dist/adapters/next.d.ts +7 -0
  10. package/dist/adapters/next.js +10 -0
  11. package/dist/adapters/next.js.map +1 -0
  12. package/dist/adapters/react-router.cjs +13 -0
  13. package/dist/adapters/react-router.cjs.map +1 -0
  14. package/dist/adapters/react-router.d.cts +10 -0
  15. package/dist/adapters/react-router.d.ts +10 -0
  16. package/dist/adapters/react-router.js +12 -0
  17. package/dist/adapters/react-router.js.map +1 -0
  18. package/dist/adapters/request.cjs +67 -0
  19. package/dist/adapters/request.cjs.map +1 -0
  20. package/dist/adapters/request.d.cts +16 -0
  21. package/dist/adapters/request.d.ts +16 -0
  22. package/dist/adapters/request.js +65 -0
  23. package/dist/adapters/request.js.map +1 -0
  24. package/dist/adapters/tanstack.cjs +13 -0
  25. package/dist/adapters/tanstack.cjs.map +1 -0
  26. package/dist/adapters/tanstack.d.cts +10 -0
  27. package/dist/adapters/tanstack.d.ts +10 -0
  28. package/dist/adapters/tanstack.js +12 -0
  29. package/dist/adapters/tanstack.js.map +1 -0
  30. package/dist/ai/index.cjs +205 -0
  31. package/dist/ai/index.cjs.map +1 -0
  32. package/dist/ai/index.d.cts +75 -0
  33. package/dist/ai/index.d.ts +75 -0
  34. package/dist/ai/index.js +195 -0
  35. package/dist/ai/index.js.map +1 -0
  36. package/dist/ai/review.cjs +319 -0
  37. package/dist/ai/review.cjs.map +1 -0
  38. package/dist/ai/review.d.cts +91 -0
  39. package/dist/ai/review.d.ts +91 -0
  40. package/dist/ai/review.js +315 -0
  41. package/dist/ai/review.js.map +1 -0
  42. package/dist/cli/bin.cjs +10 -0
  43. package/dist/cli/bin.cjs.map +1 -0
  44. package/dist/cli/bin.d.cts +1 -0
  45. package/dist/cli/bin.d.ts +1 -0
  46. package/dist/cli/bin.js +12 -0
  47. package/dist/cli/bin.js.map +1 -0
  48. package/dist/cli/index.cjs +310 -0
  49. package/dist/cli/index.cjs.map +1 -0
  50. package/dist/cli/index.d.cts +7 -0
  51. package/dist/cli/index.d.ts +7 -0
  52. package/dist/cli/index.js +309 -0
  53. package/dist/cli/index.js.map +1 -0
  54. package/dist/compiler/index.cjs +218 -0
  55. package/dist/compiler/index.cjs.map +1 -0
  56. package/dist/compiler/index.d.cts +18 -0
  57. package/dist/compiler/index.d.ts +18 -0
  58. package/dist/compiler/index.js +210 -0
  59. package/dist/compiler/index.js.map +1 -0
  60. package/dist/compiler/typescript.cjs +251 -0
  61. package/dist/compiler/typescript.cjs.map +1 -0
  62. package/dist/compiler/typescript.d.cts +27 -0
  63. package/dist/compiler/typescript.d.ts +27 -0
  64. package/dist/compiler/typescript.js +247 -0
  65. package/dist/compiler/typescript.js.map +1 -0
  66. package/dist/compiler/vite.cjs +94 -0
  67. package/dist/compiler/vite.cjs.map +1 -0
  68. package/dist/compiler/vite.d.cts +13 -0
  69. package/dist/compiler/vite.d.ts +13 -0
  70. package/dist/compiler/vite.js +92 -0
  71. package/dist/compiler/vite.js.map +1 -0
  72. package/dist/content/index.cjs +156 -0
  73. package/dist/content/index.cjs.map +1 -0
  74. package/dist/content/index.d.cts +75 -0
  75. package/dist/content/index.d.ts +75 -0
  76. package/dist/content/index.js +151 -0
  77. package/dist/content/index.js.map +1 -0
  78. package/dist/content/sanity.cjs +74 -0
  79. package/dist/content/sanity.cjs.map +1 -0
  80. package/dist/content/sanity.d.cts +19 -0
  81. package/dist/content/sanity.d.ts +19 -0
  82. package/dist/content/sanity.js +73 -0
  83. package/dist/content/sanity.js.map +1 -0
  84. package/dist/devtools/index.cjs +77 -0
  85. package/dist/devtools/index.cjs.map +1 -0
  86. package/dist/devtools/index.d.cts +29 -0
  87. package/dist/devtools/index.d.ts +29 -0
  88. package/dist/devtools/index.js +75 -0
  89. package/dist/devtools/index.js.map +1 -0
  90. package/dist/format.cjs +17 -0
  91. package/dist/format.cjs.map +1 -0
  92. package/dist/format.d.cts +9 -0
  93. package/dist/format.d.ts +9 -0
  94. package/dist/format.js +13 -0
  95. package/dist/format.js.map +1 -0
  96. package/dist/index.cjs +20 -0
  97. package/dist/index.d.cts +5 -0
  98. package/dist/index.d.ts +5 -0
  99. package/dist/index.js +5 -0
  100. package/dist/locale.cjs +158 -0
  101. package/dist/locale.cjs.map +1 -0
  102. package/dist/locale.d.cts +42 -0
  103. package/dist/locale.d.ts +42 -0
  104. package/dist/locale.js +155 -0
  105. package/dist/locale.js.map +1 -0
  106. package/dist/react/index.cjs +239 -0
  107. package/dist/react/index.cjs.map +1 -0
  108. package/dist/react/index.d.cts +105 -0
  109. package/dist/react/index.d.ts +105 -0
  110. package/dist/react/index.js +238 -0
  111. package/dist/react/index.js.map +1 -0
  112. package/dist/routing/index.cjs +381 -0
  113. package/dist/routing/index.cjs.map +1 -0
  114. package/dist/routing/index.d.cts +44 -0
  115. package/dist/routing/index.d.ts +44 -0
  116. package/dist/routing/index.js +380 -0
  117. package/dist/routing/index.js.map +1 -0
  118. package/dist/runtime.cjs +261 -0
  119. package/dist/runtime.cjs.map +1 -0
  120. package/dist/runtime.d.cts +74 -0
  121. package/dist/runtime.d.ts +74 -0
  122. package/dist/runtime.js +257 -0
  123. package/dist/runtime.js.map +1 -0
  124. package/dist/seo/index.cjs +212 -0
  125. package/dist/seo/index.cjs.map +1 -0
  126. package/dist/seo/index.d.cts +52 -0
  127. package/dist/seo/index.d.ts +52 -0
  128. package/dist/seo/index.js +209 -0
  129. package/dist/seo/index.js.map +1 -0
  130. package/dist/seo/origin.cjs +27 -0
  131. package/dist/seo/origin.cjs.map +1 -0
  132. package/dist/seo/origin.js +26 -0
  133. package/dist/seo/origin.js.map +1 -0
  134. package/dist/seo/sitemap.cjs +74 -0
  135. package/dist/seo/sitemap.cjs.map +1 -0
  136. package/dist/seo/sitemap.d.cts +16 -0
  137. package/dist/seo/sitemap.d.ts +16 -0
  138. package/dist/seo/sitemap.js +72 -0
  139. package/dist/seo/sitemap.js.map +1 -0
  140. package/dist/sources/index.cjs +227 -0
  141. package/dist/sources/index.cjs.map +1 -0
  142. package/dist/sources/index.d.cts +41 -0
  143. package/dist/sources/index.d.ts +41 -0
  144. package/dist/sources/index.js +222 -0
  145. package/dist/sources/index.js.map +1 -0
  146. package/dist/sources/node.cjs +50 -0
  147. package/dist/sources/node.cjs.map +1 -0
  148. package/dist/sources/node.d.cts +5 -0
  149. package/dist/sources/node.d.ts +5 -0
  150. package/dist/sources/node.js +49 -0
  151. package/dist/sources/node.js.map +1 -0
  152. package/package.json +256 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/ai/index.ts"],"sourcesContent":["import IntlMessageFormat from \"intl-messageformat\";\n\nexport interface TranslationSuggestionRequest {\n sourceLocale: string;\n targetLocale: string;\n key: string;\n sourceMessage: string;\n context?: string;\n terminology?: readonly string[];\n}\n\nexport interface TranslationTerminologyRule {\n /** Source substring that must be present before the target term is required. */\n source: string;\n /** Required, case-insensitive target substring in the suggestion. */\n target: string;\n weight?: number;\n}\n\nexport interface TranslationQualityCheckInput {\n request: Readonly<TranslationSuggestionRequest>;\n suggestion: string;\n}\n\nexport interface TranslationQualityCheckOutput {\n /** Quality score from 0 to 100. */\n score: number;\n message?: string;\n}\n\nexport interface TranslationQualityCheck {\n id: string;\n weight?: number;\n evaluate(\n input: Readonly<TranslationQualityCheckInput>,\n ):\n | number\n | TranslationQualityCheckOutput\n | Promise<number | TranslationQualityCheckOutput>;\n}\n\nexport interface TranslationQualityOptions {\n terminology?: readonly TranslationTerminologyRule[];\n /** Custom checks receive the request, including its optional context. */\n checks?: readonly TranslationQualityCheck[];\n}\n\nexport interface TranslationQualityCheckResult {\n id: string;\n score: number;\n weight: number;\n passed: boolean;\n message?: string;\n}\n\nexport interface TranslationQualityReport {\n /** Weighted mean of all applicable checks, rounded to the nearest integer. */\n score: number;\n checks: readonly TranslationQualityCheckResult[];\n}\n\nexport interface SuggestTranslationOptions {\n quality?: TranslationQualityOptions;\n}\n\nexport interface TranslationSuggestionProvider {\n suggest(\n request: Readonly<TranslationSuggestionRequest>,\n signal?: AbortSignal,\n ): Promise<string>;\n}\n\nexport type TranslationSuggestionAuthorizer = (\n request: Readonly<TranslationSuggestionRequest>,\n signal?: AbortSignal,\n) => boolean | Promise<boolean>;\n\nexport interface TranslationSuggestion {\n key: string;\n locale: string;\n value: string;\n approved: false;\n quality?: TranslationQualityReport;\n}\n\nexport type TranslationSuggestionErrorCode =\n | \"invalid-source\"\n | \"invalid-output\"\n | \"placeholder-mismatch\"\n | \"provider-failed\"\n | \"rate-limited\"\n | \"server-only\"\n | \"unauthorized\"\n | \"authorization-failed\"\n | \"invalid-quality-config\"\n | \"quality-check-failed\"\n | \"aborted\";\n\nexport class TranslationSuggestionError extends Error {\n constructor(\n public readonly code: TranslationSuggestionErrorCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = \"TranslationSuggestionError\";\n }\n}\n\nconst canonicalize = (locale: string): string => {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (!canonical) {\n throw new Error();\n }\n\n return canonical;\n } catch {\n throw new TranslationSuggestionError(\n \"invalid-source\",\n `Invalid BCP 47 locale \"${locale}\".`,\n );\n }\n};\n\nconst getPlaceholders = (message: string): string[] =>\n [...message.matchAll(/\\{\\s*([A-Za-z_][\\w.-]*)/g)]\n .map((match) => match[1])\n .filter((name): name is string => name !== undefined)\n .sort();\n\nconst isAbortError = (error: unknown): boolean =>\n error instanceof Error && error.name === \"AbortError\";\n\nconst assertServerOnly = (): void => {\n if (typeof window !== \"undefined\") {\n throw new TranslationSuggestionError(\n \"server-only\",\n \"Translation providers must only be called from a server environment.\",\n );\n }\n};\n\nconst createQualityReport = async (\n request: Readonly<TranslationSuggestionRequest>,\n suggestion: string,\n options: TranslationQualityOptions,\n): Promise<TranslationQualityReport> => {\n const checks: Array<{\n id: string;\n weight: number;\n evaluate: (\n input: Readonly<TranslationQualityCheckInput>,\n ) => number | TranslationQualityCheckOutput | Promise<number | TranslationQualityCheckOutput>;\n }> = [];\n const addCheck = (\n id: string,\n weight: number | undefined,\n evaluate: (input: Readonly<TranslationQualityCheckInput>) =>\n | number\n | TranslationQualityCheckOutput\n | Promise<number | TranslationQualityCheckOutput>,\n ): void => {\n const normalizedWeight = weight ?? 1;\n\n if (!Number.isFinite(normalizedWeight) || normalizedWeight <= 0) {\n throw new TranslationSuggestionError(\n \"invalid-quality-config\",\n \"Translation quality check weights must be positive finite numbers.\",\n );\n }\n\n if (!id.trim() || checks.some((check) => check.id === id)) {\n throw new TranslationSuggestionError(\n \"invalid-quality-config\",\n \"Translation quality check IDs must be unique and non-empty.\",\n );\n }\n\n checks.push({ id, weight: normalizedWeight, evaluate });\n };\n\n for (const [index, rule] of (options.terminology ?? []).entries()) {\n if (!rule.source.trim() || !rule.target.trim()) {\n throw new TranslationSuggestionError(\n \"invalid-quality-config\",\n \"Translation terminology rules require source and target terms.\",\n );\n }\n\n const sourceTerm = rule.source.toLocaleLowerCase(request.sourceLocale);\n const targetTerm = rule.target.toLocaleLowerCase(request.targetLocale);\n\n if (request.sourceMessage.toLocaleLowerCase(request.sourceLocale).includes(sourceTerm)) {\n addCheck(\n `terminology-${index + 1}`,\n rule.weight,\n () =>\n suggestion.toLocaleLowerCase(request.targetLocale).includes(targetTerm)\n ? 100\n : {\n score: 0,\n message: \"The required target term is missing from the suggestion.\",\n },\n );\n }\n }\n\n for (const check of options.checks ?? []) {\n addCheck(check.id, check.weight, check.evaluate);\n }\n\n const input = Object.freeze({ request, suggestion });\n const results = await Promise.all(\n checks.map(async (check): Promise<TranslationQualityCheckResult> => {\n let output: number | TranslationQualityCheckOutput;\n\n try {\n output = await check.evaluate(input);\n } catch (error) {\n throw new TranslationSuggestionError(\n \"quality-check-failed\",\n `Translation quality check \"${check.id}\" failed.`,\n { cause: error },\n );\n }\n\n const details =\n typeof output === \"object\" && output !== null ? output : undefined;\n const score = typeof output === \"number\" ? output : details?.score;\n\n if (typeof score !== \"number\" || !Number.isFinite(score) || score < 0 || score > 100) {\n throw new TranslationSuggestionError(\n \"quality-check-failed\",\n `Translation quality check \"${check.id}\" returned an invalid score.`,\n );\n }\n\n return Object.freeze({\n id: check.id,\n score,\n weight: check.weight,\n passed: score === 100,\n ...(details?.message ? { message: details.message } : {}),\n });\n }),\n );\n const totalWeight = checks.reduce((total, check) => total + check.weight, 0);\n const score =\n totalWeight === 0\n ? 100\n : Math.round(\n results.reduce(\n (total, result) => total + result.score * result.weight,\n 0,\n ) / totalWeight,\n );\n\n return Object.freeze({ score, checks: Object.freeze(results) });\n};\n\nexport const suggestTranslation = async (\n provider: TranslationSuggestionProvider,\n request: TranslationSuggestionRequest,\n signal?: AbortSignal,\n options: SuggestTranslationOptions = {},\n): Promise<TranslationSuggestion> => {\n assertServerOnly();\n\n if (!request.key.trim() || !request.sourceMessage.trim()) {\n throw new TranslationSuggestionError(\n \"invalid-source\",\n \"A translation key and non-empty source message are required.\",\n );\n }\n\n const sourceLocale = canonicalize(request.sourceLocale);\n const targetLocale = canonicalize(request.targetLocale);\n const normalizedRequest = Object.freeze({\n ...request,\n sourceLocale,\n targetLocale,\n terminology: request.terminology\n ? Object.freeze([...request.terminology])\n : undefined,\n });\n const qualityOptions = options.quality;\n\n if (qualityOptions) {\n const checkIds = new Set<string>();\n for (const [index, rule] of (qualityOptions.terminology ?? []).entries()) {\n if (\n typeof rule.source !== \"string\" ||\n typeof rule.target !== \"string\" ||\n !rule.source.trim() ||\n !rule.target.trim() ||\n (rule.weight !== undefined &&\n (!Number.isFinite(rule.weight) || rule.weight <= 0))\n ) {\n throw new TranslationSuggestionError(\n \"invalid-quality-config\",\n \"Translation terminology rules require non-empty terms and positive finite weights.\",\n );\n }\n\n if (\n normalizedRequest.sourceMessage\n .toLocaleLowerCase(sourceLocale)\n .includes(rule.source.toLocaleLowerCase(sourceLocale))\n ) {\n checkIds.add(`terminology-${index + 1}`);\n }\n }\n\n for (const check of qualityOptions.checks ?? []) {\n const id = check.id;\n\n if (\n typeof id !== \"string\" ||\n !id.trim() ||\n checkIds.has(id) ||\n typeof check.evaluate !== \"function\"\n ) {\n throw new TranslationSuggestionError(\n \"invalid-quality-config\",\n \"Translation quality checks require unique non-empty IDs and an evaluator.\",\n );\n }\n\n checkIds.add(id);\n\n if (\n check.weight !== undefined &&\n (!Number.isFinite(check.weight) || check.weight <= 0)\n ) {\n throw new TranslationSuggestionError(\n \"invalid-quality-config\",\n \"Translation quality check weights must be positive finite numbers.\",\n );\n }\n }\n }\n\n try {\n new IntlMessageFormat(normalizedRequest.sourceMessage, sourceLocale);\n } catch (error) {\n throw new TranslationSuggestionError(\n \"invalid-source\",\n `The source message for \"${request.key}\" has invalid ICU syntax.`,\n { cause: error },\n );\n }\n\n if (signal?.aborted) {\n throw new TranslationSuggestionError(\n \"aborted\",\n `Translation suggestion for \"${request.key}\" was aborted.`,\n { cause: signal.reason },\n );\n }\n\n let suggestion: string;\n\n try {\n suggestion = await provider.suggest(normalizedRequest, signal);\n } catch (error) {\n if (error instanceof TranslationSuggestionError) {\n throw error;\n }\n\n if (signal?.aborted || isAbortError(error)) {\n throw new TranslationSuggestionError(\n \"aborted\",\n `Translation suggestion for \"${request.key}\" was aborted.`,\n { cause: error },\n );\n }\n\n throw new TranslationSuggestionError(\n \"provider-failed\",\n `The translation provider failed for \"${request.key}\".`,\n { cause: error },\n );\n }\n\n if (typeof suggestion !== \"string\" || !suggestion.trim()) {\n throw new TranslationSuggestionError(\n \"invalid-output\",\n `The translation provider returned an empty or non-text suggestion for \"${request.key}\".`,\n );\n }\n\n try {\n new IntlMessageFormat(suggestion, targetLocale);\n } catch (error) {\n throw new TranslationSuggestionError(\n \"invalid-output\",\n `The translation provider returned invalid message syntax for \"${request.key}\".`,\n { cause: error },\n );\n }\n\n const sourcePlaceholders = getPlaceholders(normalizedRequest.sourceMessage);\n const translatedPlaceholders = getPlaceholders(suggestion);\n\n if (\n sourcePlaceholders.length !== translatedPlaceholders.length ||\n sourcePlaceholders.some(\n (placeholder, index) => placeholder !== translatedPlaceholders[index],\n )\n ) {\n throw new TranslationSuggestionError(\n \"placeholder-mismatch\",\n `The translation provider changed placeholders for \"${request.key}\".`,\n );\n }\n\n const quality = qualityOptions\n ? await createQualityReport(normalizedRequest, suggestion, qualityOptions)\n : undefined;\n\n return Object.freeze({\n key: normalizedRequest.key,\n locale: targetLocale,\n value: suggestion,\n approved: false,\n ...(quality ? { quality } : {}),\n });\n};\n\n/** Calls authorize for every server-side suggestion and fails closed. */\nexport const createAuthorizedSuggestionProvider = (\n provider: TranslationSuggestionProvider,\n authorize: TranslationSuggestionAuthorizer,\n): TranslationSuggestionProvider => ({\n async suggest(request, signal) {\n assertServerOnly();\n\n if (signal?.aborted) {\n throw new TranslationSuggestionError(\n \"aborted\",\n \"Translation suggestion authorization was aborted.\",\n { cause: signal.reason },\n );\n }\n\n const authorizedRequest = Object.freeze({\n ...request,\n terminology: request.terminology\n ? Object.freeze([...request.terminology])\n : undefined,\n });\n let authorized: boolean;\n\n try {\n authorized = await authorize(authorizedRequest, signal);\n } catch (error) {\n if (signal?.aborted || isAbortError(error)) {\n throw new TranslationSuggestionError(\n \"aborted\",\n \"Translation suggestion authorization was aborted.\",\n { cause: error },\n );\n }\n\n throw new TranslationSuggestionError(\n \"authorization-failed\",\n \"Translation suggestion authorization failed.\",\n );\n }\n\n if (signal?.aborted) {\n throw new TranslationSuggestionError(\n \"aborted\",\n \"Translation suggestion authorization was aborted.\",\n { cause: signal.reason },\n );\n }\n\n if (authorized !== true) {\n throw new TranslationSuggestionError(\n \"unauthorized\",\n \"The caller is not authorized to request this translation suggestion.\",\n );\n }\n\n return provider.suggest(authorizedRequest, signal);\n },\n});\n\nexport interface RateLimitedProviderOptions {\n maxConcurrent?: number;\n minIntervalMs?: number;\n}\n\nconst abortableDelay = (delay: number, signal?: AbortSignal): Promise<void> =>\n new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(\n new TranslationSuggestionError(\n \"aborted\",\n \"Translation provider request was aborted.\",\n { cause: signal.reason },\n ),\n );\n return;\n }\n\n let timer: ReturnType<typeof setTimeout>;\n const onAbort = () => {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", onAbort);\n reject(\n new TranslationSuggestionError(\n \"aborted\",\n \"Translation provider request was aborted.\",\n { cause: signal?.reason },\n ),\n );\n };\n\n timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, delay);\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n\nexport const createRateLimitedSuggestionProvider = (\n provider: TranslationSuggestionProvider,\n options: RateLimitedProviderOptions = {},\n): TranslationSuggestionProvider => {\n const maxConcurrent = options.maxConcurrent ?? 2;\n const minIntervalMs = options.minIntervalMs ?? 0;\n\n if (!Number.isInteger(maxConcurrent) || maxConcurrent < 1) {\n throw new Error(\"maxConcurrent must be a positive integer.\");\n }\n\n if (!Number.isFinite(minIntervalMs) || minIntervalMs < 0) {\n throw new Error(\"minIntervalMs must be a non-negative finite number.\");\n }\n\n let activeRequests = 0;\n let nextStartAt = 0;\n\n return {\n async suggest(request, signal) {\n assertServerOnly();\n\n if (activeRequests >= maxConcurrent) {\n throw new TranslationSuggestionError(\n \"rate-limited\",\n \"The translation provider concurrency limit was reached.\",\n );\n }\n\n activeRequests += 1;\n const startAt = Math.max(Date.now(), nextStartAt);\n nextStartAt = startAt + minIntervalMs;\n\n try {\n const delay = startAt - Date.now();\n\n if (delay > 0) {\n await abortableDelay(delay, signal);\n } else if (signal?.aborted) {\n throw new TranslationSuggestionError(\n \"aborted\",\n \"Translation provider request was aborted.\",\n { cause: signal.reason },\n );\n }\n\n return await provider.suggest(request, signal);\n } finally {\n activeRequests -= 1;\n }\n },\n };\n};\n\nexport {\n createInMemoryTranslationReviewStore,\n createTransactionalTranslationReviewStore,\n createTranslationReviewWorkflow,\n TranslationReviewConflictError,\n} from \"./review\";\nexport type {\n TransactionalTranslationReviewPersistence,\n TransactionalTranslationReviewTransaction,\n TranslationReviewAuditRecord,\n TranslationReviewRecord,\n TranslationReviewStatus,\n TranslationReviewStore,\n TranslationReviewWorkflow,\n CreateTransactionalTranslationReviewStoreOptions,\n VersionedTranslation,\n} from \"./review\";\n"],"mappings":";;;AAkGA,IAAa,6BAAb,cAAgD,MAAM;CAElC;CADlB,YACE,MACA,SACA,SACA;EACA,MAAM,SAAS,OAAO;EAJN,KAAA,OAAA;EAKhB,KAAK,OAAO;CACd;AACF;AAEA,MAAM,gBAAgB,WAA2B;CAC/C,IAAI;EACF,MAAM,CAAC,aAAa,KAAK,oBAAoB,MAAM;EAEnD,IAAI,CAAC,WACH,MAAM,IAAI,MAAM;EAGlB,OAAO;CACT,QAAQ;EACN,MAAM,IAAI,2BACR,kBACA,0BAA0B,OAAO,GACnC;CACF;AACF;AAEA,MAAM,mBAAmB,YACvB,CAAC,GAAG,QAAQ,SAAS,0BAA0B,CAAC,CAAC,CAC9C,KAAK,UAAU,MAAM,EAAE,CAAC,CACxB,QAAQ,SAAyB,SAAS,KAAA,CAAS,CAAC,CACpD,KAAK;AAEV,MAAM,gBAAgB,UACpB,iBAAiB,SAAS,MAAM,SAAS;AAE3C,MAAM,yBAA+B;CACnC,IAAI,OAAO,WAAW,aACpB,MAAM,IAAI,2BACR,eACA,sEACF;AAEJ;AAEA,MAAM,sBAAsB,OAC1B,SACA,YACA,YACsC;CACtC,MAAM,SAMD,CAAC;CACN,MAAM,YACJ,IACA,QACA,aAIS;EACT,MAAM,mBAAmB,UAAU;EAEnC,IAAI,CAAC,OAAO,SAAS,gBAAgB,KAAK,oBAAoB,GAC5D,MAAM,IAAI,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M,IAAI,2BACR,WACA,6CACA,EAAE,OAAO,OAAO,OAAO,CACzB;GAGF,OAAO,MAAM,SAAS,QAAQ,SAAS,MAAM;EAC/C,UAAU;GACR,kBAAkB;EACpB;CACF,EACF;AACF"}
@@ -0,0 +1,319 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_ai_index = require("./index.cjs");
3
+ // src/ai/review.ts
4
+ var TranslationReviewConflictError = class extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "TranslationReviewConflictError";
8
+ }
9
+ };
10
+ const translationId = (locale, key) => `${locale}\u0000${key}`;
11
+ const immutable = (value) => Object.freeze({ ...value });
12
+ const requireReviewer = (reviewer) => {
13
+ const normalized = reviewer.trim();
14
+ if (!normalized) throw new Error("A reviewer identity is required.");
15
+ return normalized;
16
+ };
17
+ const timestamp = (clock) => clock().toISOString();
18
+ const canonicalLocale = (locale) => {
19
+ try {
20
+ const [canonical] = Intl.getCanonicalLocales(locale);
21
+ if (canonical) return canonical;
22
+ } catch {}
23
+ throw new require_ai_index.TranslationSuggestionError("invalid-source", `Invalid BCP 47 locale "${locale}".`);
24
+ };
25
+ const assertServerOnly = () => {
26
+ if (typeof window !== "undefined") throw new require_ai_index.TranslationSuggestionError("server-only", "Translation review workflows must only be used from a server environment.");
27
+ };
28
+ const createInMemoryTranslationReviewStore = (options = {}) => {
29
+ const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
30
+ const translations = /* @__PURE__ */ new Map();
31
+ const suggestions = /* @__PURE__ */ new Map();
32
+ const auditTrail = [];
33
+ return {
34
+ async getTranslation(locale, key) {
35
+ const current = translations.get(translationId(locale, key));
36
+ return current ? immutable(current) : void 0;
37
+ },
38
+ async getSuggestion(id) {
39
+ const record = suggestions.get(id);
40
+ return record ? immutable(record) : void 0;
41
+ },
42
+ async createPendingSuggestion(record) {
43
+ if (suggestions.has(record.id)) throw new TranslationReviewConflictError(`Suggestion "${record.id}" already exists.`);
44
+ const revision = translations.get(translationId(record.locale, record.key))?.revision ?? 0;
45
+ if (revision !== record.baseRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed while its suggestion was being created.`);
46
+ suggestions.set(record.id, immutable(record));
47
+ auditTrail.push(immutable({
48
+ suggestionId: record.id,
49
+ key: record.key,
50
+ locale: record.locale,
51
+ action: "suggested",
52
+ actor: "ai",
53
+ at: timestamp(clock),
54
+ previousRevision: revision,
55
+ revision,
56
+ value: record.value
57
+ }));
58
+ },
59
+ async approveSuggestion(id, reviewer, expectedRevision) {
60
+ const record = suggestions.get(id);
61
+ if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
62
+ if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
63
+ const currentKey = translationId(record.locale, record.key);
64
+ const current = translations.get(currentKey);
65
+ const currentRevision = current?.revision ?? 0;
66
+ if (record.baseRevision !== expectedRevision || currentRevision !== expectedRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed after the suggestion was created.`);
67
+ const at = timestamp(clock);
68
+ const normalizedReviewer = requireReviewer(reviewer);
69
+ const translation = immutable({
70
+ key: record.key,
71
+ locale: record.locale,
72
+ value: record.value,
73
+ revision: currentRevision + 1
74
+ });
75
+ const suggestion = immutable({
76
+ ...record,
77
+ status: "approved",
78
+ reviewedAt: at,
79
+ reviewedBy: normalizedReviewer
80
+ });
81
+ translations.set(currentKey, translation);
82
+ suggestions.set(id, suggestion);
83
+ auditTrail.push(immutable({
84
+ suggestionId: id,
85
+ key: record.key,
86
+ locale: record.locale,
87
+ action: "approved",
88
+ actor: normalizedReviewer,
89
+ at,
90
+ previousRevision: currentRevision,
91
+ revision: translation.revision,
92
+ previousValue: current?.value,
93
+ value: translation.value
94
+ }));
95
+ return {
96
+ suggestion: immutable(suggestion),
97
+ translation: immutable(translation)
98
+ };
99
+ },
100
+ async rejectSuggestion(id, reviewer, reason) {
101
+ const record = suggestions.get(id);
102
+ if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
103
+ if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
104
+ const normalizedReviewer = requireReviewer(reviewer);
105
+ const at = timestamp(clock);
106
+ const normalizedReason = reason?.trim() || void 0;
107
+ const suggestion = immutable({
108
+ ...record,
109
+ status: "rejected",
110
+ reviewedAt: at,
111
+ reviewedBy: normalizedReviewer,
112
+ rejectionReason: normalizedReason
113
+ });
114
+ suggestions.set(id, suggestion);
115
+ auditTrail.push(immutable({
116
+ suggestionId: id,
117
+ key: record.key,
118
+ locale: record.locale,
119
+ action: "rejected",
120
+ actor: normalizedReviewer,
121
+ at,
122
+ previousRevision: record.baseRevision,
123
+ revision: record.baseRevision,
124
+ value: record.value,
125
+ reason: normalizedReason
126
+ }));
127
+ return immutable(suggestion);
128
+ },
129
+ async listAuditTrail() {
130
+ return Object.freeze(auditTrail.map((record) => immutable(record)));
131
+ }
132
+ };
133
+ };
134
+ const createTransactionalTranslationReviewStore = (persistence, options = {}) => {
135
+ const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
136
+ return {
137
+ getTranslation(locale, key) {
138
+ assertServerOnly();
139
+ return persistence.transaction(async (transaction) => {
140
+ const translation = await transaction.getTranslation(locale, key);
141
+ return translation ? immutable(translation) : void 0;
142
+ });
143
+ },
144
+ getSuggestion(id) {
145
+ assertServerOnly();
146
+ return persistence.transaction(async (transaction) => {
147
+ const suggestion = await transaction.getSuggestion(id);
148
+ return suggestion ? immutable(suggestion) : void 0;
149
+ });
150
+ },
151
+ async createPendingSuggestion(record) {
152
+ assertServerOnly();
153
+ await persistence.transaction(async (transaction) => {
154
+ if (await transaction.getSuggestion(record.id)) throw new TranslationReviewConflictError(`Suggestion "${record.id}" already exists.`);
155
+ const revision = (await transaction.getTranslation(record.locale, record.key))?.revision ?? 0;
156
+ if (revision !== record.baseRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed while its suggestion was being created.`);
157
+ if (!await transaction.insertSuggestionIfAbsent(immutable(record))) throw new TranslationReviewConflictError(`Suggestion "${record.id}" already exists.`);
158
+ await transaction.appendAuditRecord(immutable({
159
+ suggestionId: record.id,
160
+ key: record.key,
161
+ locale: record.locale,
162
+ action: "suggested",
163
+ actor: "ai",
164
+ at: timestamp(clock),
165
+ previousRevision: revision,
166
+ revision,
167
+ value: record.value
168
+ }));
169
+ });
170
+ },
171
+ approveSuggestion(id, reviewer, expectedRevision) {
172
+ assertServerOnly();
173
+ return persistence.transaction(async (transaction) => {
174
+ const record = await transaction.getSuggestion(id);
175
+ if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
176
+ if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
177
+ const current = await transaction.getTranslation(record.locale, record.key);
178
+ const currentRevision = current?.revision ?? 0;
179
+ if (record.baseRevision !== expectedRevision || currentRevision !== expectedRevision) throw new TranslationReviewConflictError(`Translation "${record.key}" changed after the suggestion was created.`);
180
+ const normalizedReviewer = requireReviewer(reviewer);
181
+ const at = timestamp(clock);
182
+ const translation = immutable({
183
+ key: record.key,
184
+ locale: record.locale,
185
+ value: record.value,
186
+ revision: currentRevision + 1
187
+ });
188
+ const suggestion = immutable({
189
+ ...record,
190
+ status: "approved",
191
+ reviewedAt: at,
192
+ reviewedBy: normalizedReviewer
193
+ });
194
+ if (!await transaction.compareAndSetTranslation(record.locale, record.key, expectedRevision, translation)) throw new TranslationReviewConflictError(`Translation "${record.key}" changed after the suggestion was created.`);
195
+ if (!await transaction.updateSuggestionIfPending(id, suggestion)) throw new TranslationReviewConflictError(`Suggestion "${id}" is no longer pending.`);
196
+ await transaction.appendAuditRecord(immutable({
197
+ suggestionId: id,
198
+ key: record.key,
199
+ locale: record.locale,
200
+ action: "approved",
201
+ actor: normalizedReviewer,
202
+ at,
203
+ previousRevision: currentRevision,
204
+ revision: translation.revision,
205
+ previousValue: current?.value,
206
+ value: translation.value
207
+ }));
208
+ return {
209
+ suggestion: immutable(suggestion),
210
+ translation: immutable(translation)
211
+ };
212
+ });
213
+ },
214
+ rejectSuggestion(id, reviewer, reason) {
215
+ assertServerOnly();
216
+ return persistence.transaction(async (transaction) => {
217
+ const record = await transaction.getSuggestion(id);
218
+ if (!record) throw new Error(`Unknown translation suggestion "${id}".`);
219
+ if (record.status !== "pending") throw new TranslationReviewConflictError(`Suggestion "${id}" is already ${record.status}.`);
220
+ const normalizedReviewer = requireReviewer(reviewer);
221
+ const at = timestamp(clock);
222
+ const normalizedReason = reason?.trim() || void 0;
223
+ const suggestion = immutable({
224
+ ...record,
225
+ status: "rejected",
226
+ reviewedAt: at,
227
+ reviewedBy: normalizedReviewer,
228
+ rejectionReason: normalizedReason
229
+ });
230
+ if (!await transaction.updateSuggestionIfPending(id, suggestion)) throw new TranslationReviewConflictError(`Suggestion "${id}" is no longer pending.`);
231
+ await transaction.appendAuditRecord(immutable({
232
+ suggestionId: id,
233
+ key: record.key,
234
+ locale: record.locale,
235
+ action: "rejected",
236
+ actor: normalizedReviewer,
237
+ at,
238
+ previousRevision: record.baseRevision,
239
+ revision: record.baseRevision,
240
+ value: record.value,
241
+ reason: normalizedReason
242
+ }));
243
+ return immutable(suggestion);
244
+ });
245
+ },
246
+ listAuditTrail() {
247
+ assertServerOnly();
248
+ return persistence.transaction(async (transaction) => Object.freeze((await transaction.listAuditTrail()).map((record) => immutable(record))));
249
+ }
250
+ };
251
+ };
252
+ const createId = () => {
253
+ const cryptoApi = globalThis.crypto;
254
+ if (!cryptoApi?.randomUUID) throw new Error("A secure random UUID implementation is required to create suggestions.");
255
+ return cryptoApi.randomUUID();
256
+ };
257
+ const createTranslationReviewWorkflow = (provider, store, options = {}) => {
258
+ const idFactory = options.idFactory ?? createId;
259
+ const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
260
+ return {
261
+ async suggest(request, signal) {
262
+ assertServerOnly();
263
+ const sourceLocale = canonicalLocale(request.sourceLocale);
264
+ const targetLocale = canonicalLocale(request.targetLocale);
265
+ const workflowRequest = Object.freeze({
266
+ ...request,
267
+ sourceLocale,
268
+ targetLocale,
269
+ terminology: request.terminology ? Object.freeze([...request.terminology]) : void 0
270
+ });
271
+ const current = await store.getTranslation(targetLocale, workflowRequest.key);
272
+ const suggestion = await require_ai_index.suggestTranslation(provider, workflowRequest, signal, { quality: options.quality });
273
+ const id = idFactory();
274
+ if (!id.trim()) throw new Error("Suggestion IDs must not be empty.");
275
+ const record = immutable({
276
+ id,
277
+ key: suggestion.key,
278
+ locale: suggestion.locale,
279
+ sourceLocale,
280
+ sourceMessage: workflowRequest.sourceMessage,
281
+ value: suggestion.value,
282
+ baseRevision: current?.revision ?? 0,
283
+ status: "pending",
284
+ createdAt: timestamp(clock),
285
+ ...suggestion.quality ? { quality: suggestion.quality } : {}
286
+ });
287
+ await store.createPendingSuggestion(record);
288
+ return record;
289
+ },
290
+ async approve(id, reviewer) {
291
+ assertServerOnly();
292
+ const suggestion = await store.getSuggestion(id);
293
+ if (!suggestion) throw new Error(`Unknown translation suggestion "${id}".`);
294
+ return store.approveSuggestion(id, reviewer, suggestion.baseRevision);
295
+ },
296
+ reject(id, reviewer, reason) {
297
+ assertServerOnly();
298
+ return store.rejectSuggestion(id, reviewer, reason);
299
+ },
300
+ getSuggestion(id) {
301
+ assertServerOnly();
302
+ return store.getSuggestion(id);
303
+ },
304
+ getTranslation(locale, key) {
305
+ assertServerOnly();
306
+ return store.getTranslation(locale, key);
307
+ },
308
+ listAuditTrail() {
309
+ assertServerOnly();
310
+ return store.listAuditTrail();
311
+ }
312
+ };
313
+ };
314
+ exports.TranslationReviewConflictError = TranslationReviewConflictError;
315
+ exports.createInMemoryTranslationReviewStore = createInMemoryTranslationReviewStore;
316
+ exports.createTransactionalTranslationReviewStore = createTransactionalTranslationReviewStore;
317
+ exports.createTranslationReviewWorkflow = createTranslationReviewWorkflow;
318
+
319
+ //# sourceMappingURL=review.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review.cjs","names":["TranslationSuggestionError","suggestTranslation"],"sources":["../../src/ai/review.ts"],"sourcesContent":["import {\n suggestTranslation,\n type SuggestTranslationOptions,\n type TranslationQualityReport,\n TranslationSuggestionError,\n type TranslationSuggestionProvider,\n type TranslationSuggestionRequest,\n} from \"./index\";\n\nexport type TranslationReviewStatus = \"pending\" | \"approved\" | \"rejected\";\n\nexport interface VersionedTranslation {\n readonly key: string;\n readonly locale: string;\n readonly value: string;\n readonly revision: number;\n}\n\nexport interface TranslationReviewRecord {\n readonly id: string;\n readonly key: string;\n readonly locale: string;\n readonly sourceLocale: string;\n readonly sourceMessage: string;\n readonly value: string;\n readonly baseRevision: number;\n readonly status: TranslationReviewStatus;\n readonly createdAt: string;\n readonly quality?: TranslationQualityReport;\n readonly reviewedAt?: string;\n readonly reviewedBy?: string;\n readonly rejectionReason?: string;\n}\n\nexport interface TranslationReviewAuditRecord {\n readonly suggestionId: string;\n readonly key: string;\n readonly locale: string;\n readonly action: \"suggested\" | \"approved\" | \"rejected\";\n readonly actor: string;\n readonly at: string;\n readonly previousRevision: number;\n readonly revision: number;\n readonly previousValue?: string;\n readonly value: string;\n readonly reason?: string;\n}\n\nexport class TranslationReviewConflictError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"TranslationReviewConflictError\";\n }\n}\n\nexport interface TranslationReviewStore {\n getTranslation(\n locale: string,\n key: string,\n ): Promise<VersionedTranslation | undefined>;\n getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;\n createPendingSuggestion(record: TranslationReviewRecord): Promise<void>;\n approveSuggestion(\n id: string,\n reviewer: string,\n expectedRevision: number,\n ): Promise<{\n suggestion: TranslationReviewRecord;\n translation: VersionedTranslation;\n }>;\n rejectSuggestion(\n id: string,\n reviewer: string,\n reason?: string,\n ): Promise<TranslationReviewRecord>;\n listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;\n}\n\nexport interface TransactionalTranslationReviewTransaction {\n getTranslation(\n locale: string,\n key: string,\n ): Promise<VersionedTranslation | undefined>;\n getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;\n /** Atomically inserts the record only when its ID is unused. */\n insertSuggestionIfAbsent(\n record: TranslationReviewRecord,\n ): Promise<boolean>;\n /** Atomically updates the record only while its stored status is pending. */\n updateSuggestionIfPending(\n id: string,\n record: TranslationReviewRecord,\n ): Promise<boolean>;\n /** Atomically writes only when the current revision equals expectedRevision. */\n compareAndSetTranslation(\n locale: string,\n key: string,\n expectedRevision: number,\n translation: VersionedTranslation,\n ): Promise<boolean>;\n appendAuditRecord(record: TranslationReviewAuditRecord): Promise<void>;\n listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;\n}\n\nexport interface TransactionalTranslationReviewPersistence {\n /** Commits all callback writes together and rolls them back if it throws. */\n transaction<Result>(\n operation: (\n transaction: TransactionalTranslationReviewTransaction,\n ) => Promise<Result>,\n ): Promise<Result>;\n}\n\nexport interface CreateInMemoryTranslationReviewStoreOptions {\n clock?: () => Date;\n}\n\nconst translationId = (locale: string, key: string): string =>\n `${locale}\\u0000${key}`;\n\nconst immutable = <Value extends object>(value: Value): Readonly<Value> =>\n Object.freeze({ ...value });\n\nconst requireReviewer = (reviewer: string): string => {\n const normalized = reviewer.trim();\n\n if (!normalized) {\n throw new Error(\"A reviewer identity is required.\");\n }\n\n return normalized;\n};\n\nconst timestamp = (clock: () => Date): string => clock().toISOString();\n\nconst canonicalLocale = (locale: string): string => {\n try {\n const [canonical] = Intl.getCanonicalLocales(locale);\n\n if (canonical) {\n return canonical;\n }\n } catch {\n // Let the caller handle invalid locale values as a typed suggestion error.\n }\n\n throw new TranslationSuggestionError(\n \"invalid-source\",\n `Invalid BCP 47 locale \"${locale}\".`,\n );\n};\n\nconst assertServerOnly = (): void => {\n if (typeof window !== \"undefined\") {\n throw new TranslationSuggestionError(\n \"server-only\",\n \"Translation review workflows must only be used from a server environment.\",\n );\n }\n};\n\nexport const createInMemoryTranslationReviewStore = (\n options: CreateInMemoryTranslationReviewStoreOptions = {},\n): TranslationReviewStore => {\n const clock = options.clock ?? (() => new Date());\n const translations = new Map<string, VersionedTranslation>();\n const suggestions = new Map<string, TranslationReviewRecord>();\n const auditTrail: TranslationReviewAuditRecord[] = [];\n\n return {\n async getTranslation(locale, key) {\n const current = translations.get(translationId(locale, key));\n return current ? immutable(current) : undefined;\n },\n\n async getSuggestion(id) {\n const record = suggestions.get(id);\n return record ? immutable(record) : undefined;\n },\n\n async createPendingSuggestion(record) {\n if (suggestions.has(record.id)) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${record.id}\" already exists.`,\n );\n }\n\n const current =\n translations.get(translationId(record.locale, record.key));\n const revision = current?.revision ?? 0;\n\n if (revision !== record.baseRevision) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed while its suggestion was being created.`,\n );\n }\n\n suggestions.set(record.id, immutable(record));\n auditTrail.push(\n immutable({\n suggestionId: record.id,\n key: record.key,\n locale: record.locale,\n action: \"suggested\" as const,\n actor: \"ai\",\n at: timestamp(clock),\n previousRevision: revision,\n revision,\n value: record.value,\n }),\n );\n },\n\n async approveSuggestion(id, reviewer, expectedRevision) {\n const record = suggestions.get(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const currentKey = translationId(record.locale, record.key);\n const current = translations.get(currentKey);\n const currentRevision = current?.revision ?? 0;\n\n if (\n record.baseRevision !== expectedRevision ||\n currentRevision !== expectedRevision\n ) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed after the suggestion was created.`,\n );\n }\n\n const at = timestamp(clock);\n const normalizedReviewer = requireReviewer(reviewer);\n const translation = immutable({\n key: record.key,\n locale: record.locale,\n value: record.value,\n revision: currentRevision + 1,\n });\n const suggestion = immutable({\n ...record,\n status: \"approved\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n });\n\n translations.set(currentKey, translation);\n suggestions.set(id, suggestion);\n auditTrail.push(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"approved\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: currentRevision,\n revision: translation.revision,\n previousValue: current?.value,\n value: translation.value,\n }),\n );\n\n return {\n suggestion: immutable(suggestion),\n translation: immutable(translation),\n };\n },\n\n async rejectSuggestion(id, reviewer, reason) {\n const record = suggestions.get(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const normalizedReviewer = requireReviewer(reviewer);\n const at = timestamp(clock);\n const normalizedReason = reason?.trim() || undefined;\n const suggestion = immutable({\n ...record,\n status: \"rejected\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n rejectionReason: normalizedReason,\n });\n\n suggestions.set(id, suggestion);\n auditTrail.push(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"rejected\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: record.baseRevision,\n revision: record.baseRevision,\n value: record.value,\n reason: normalizedReason,\n }),\n );\n\n return immutable(suggestion);\n },\n\n async listAuditTrail() {\n return Object.freeze(auditTrail.map((record) => immutable(record)));\n },\n };\n};\n\nexport interface CreateTransactionalTranslationReviewStoreOptions {\n clock?: () => Date;\n}\n\nexport const createTransactionalTranslationReviewStore = (\n persistence: TransactionalTranslationReviewPersistence,\n options: CreateTransactionalTranslationReviewStoreOptions = {},\n): TranslationReviewStore => {\n const clock = options.clock ?? (() => new Date());\n\n return {\n getTranslation(locale, key) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const translation = await transaction.getTranslation(locale, key);\n return translation ? immutable(translation) : undefined;\n });\n },\n\n getSuggestion(id) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const suggestion = await transaction.getSuggestion(id);\n return suggestion ? immutable(suggestion) : undefined;\n });\n },\n\n async createPendingSuggestion(record) {\n assertServerOnly();\n await persistence.transaction(async (transaction) => {\n if (await transaction.getSuggestion(record.id)) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${record.id}\" already exists.`,\n );\n }\n\n const current = await transaction.getTranslation(\n record.locale,\n record.key,\n );\n const revision = current?.revision ?? 0;\n\n if (revision !== record.baseRevision) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed while its suggestion was being created.`,\n );\n }\n\n if (!(await transaction.insertSuggestionIfAbsent(immutable(record)))) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${record.id}\" already exists.`,\n );\n }\n\n await transaction.appendAuditRecord(\n immutable({\n suggestionId: record.id,\n key: record.key,\n locale: record.locale,\n action: \"suggested\" as const,\n actor: \"ai\",\n at: timestamp(clock),\n previousRevision: revision,\n revision,\n value: record.value,\n }),\n );\n });\n },\n\n approveSuggestion(id, reviewer, expectedRevision) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const record = await transaction.getSuggestion(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const current = await transaction.getTranslation(\n record.locale,\n record.key,\n );\n const currentRevision = current?.revision ?? 0;\n\n if (\n record.baseRevision !== expectedRevision ||\n currentRevision !== expectedRevision\n ) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed after the suggestion was created.`,\n );\n }\n\n const normalizedReviewer = requireReviewer(reviewer);\n const at = timestamp(clock);\n const translation = immutable({\n key: record.key,\n locale: record.locale,\n value: record.value,\n revision: currentRevision + 1,\n });\n const suggestion = immutable({\n ...record,\n status: \"approved\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n });\n\n if (\n !(await transaction.compareAndSetTranslation(\n record.locale,\n record.key,\n expectedRevision,\n translation,\n ))\n ) {\n throw new TranslationReviewConflictError(\n `Translation \"${record.key}\" changed after the suggestion was created.`,\n );\n }\n\n if (!(await transaction.updateSuggestionIfPending(id, suggestion))) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is no longer pending.`,\n );\n }\n\n await transaction.appendAuditRecord(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"approved\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: currentRevision,\n revision: translation.revision,\n previousValue: current?.value,\n value: translation.value,\n }),\n );\n\n return {\n suggestion: immutable(suggestion),\n translation: immutable(translation),\n };\n });\n },\n\n rejectSuggestion(id, reviewer, reason) {\n assertServerOnly();\n return persistence.transaction(async (transaction) => {\n const record = await transaction.getSuggestion(id);\n\n if (!record) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n if (record.status !== \"pending\") {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is already ${record.status}.`,\n );\n }\n\n const normalizedReviewer = requireReviewer(reviewer);\n const at = timestamp(clock);\n const normalizedReason = reason?.trim() || undefined;\n const suggestion = immutable({\n ...record,\n status: \"rejected\" as const,\n reviewedAt: at,\n reviewedBy: normalizedReviewer,\n rejectionReason: normalizedReason,\n });\n\n if (!(await transaction.updateSuggestionIfPending(id, suggestion))) {\n throw new TranslationReviewConflictError(\n `Suggestion \"${id}\" is no longer pending.`,\n );\n }\n\n await transaction.appendAuditRecord(\n immutable({\n suggestionId: id,\n key: record.key,\n locale: record.locale,\n action: \"rejected\" as const,\n actor: normalizedReviewer,\n at,\n previousRevision: record.baseRevision,\n revision: record.baseRevision,\n value: record.value,\n reason: normalizedReason,\n }),\n );\n\n return immutable(suggestion);\n });\n },\n\n listAuditTrail() {\n assertServerOnly();\n return persistence.transaction(async (transaction) =>\n Object.freeze(\n (await transaction.listAuditTrail()).map((record) =>\n immutable(record),\n ),\n ),\n );\n },\n };\n};\n\nexport interface CreateTranslationReviewWorkflowOptions {\n idFactory?: () => string;\n clock?: () => Date;\n quality?: SuggestTranslationOptions[\"quality\"];\n}\n\nexport interface TranslationReviewWorkflow {\n suggest(\n request: TranslationSuggestionRequest,\n signal?: AbortSignal,\n ): Promise<TranslationReviewRecord>;\n approve(\n id: string,\n reviewer: string,\n ): Promise<{\n suggestion: TranslationReviewRecord;\n translation: VersionedTranslation;\n }>;\n reject(\n id: string,\n reviewer: string,\n reason?: string,\n ): Promise<TranslationReviewRecord>;\n getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;\n getTranslation(\n locale: string,\n key: string,\n ): Promise<VersionedTranslation | undefined>;\n listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;\n}\n\nconst createId = (): string => {\n const cryptoApi = globalThis.crypto;\n\n if (!cryptoApi?.randomUUID) {\n throw new Error(\n \"A secure random UUID implementation is required to create suggestions.\",\n );\n }\n\n return cryptoApi.randomUUID();\n};\n\nexport const createTranslationReviewWorkflow = (\n provider: TranslationSuggestionProvider,\n store: TranslationReviewStore,\n options: CreateTranslationReviewWorkflowOptions = {},\n): TranslationReviewWorkflow => {\n const idFactory = options.idFactory ?? createId;\n const clock = options.clock ?? (() => new Date());\n\n return {\n async suggest(request, signal) {\n assertServerOnly();\n const sourceLocale = canonicalLocale(request.sourceLocale);\n const targetLocale = canonicalLocale(request.targetLocale);\n const workflowRequest = Object.freeze({\n ...request,\n sourceLocale,\n targetLocale,\n terminology: request.terminology\n ? Object.freeze([...request.terminology])\n : undefined,\n });\n const current = await store.getTranslation(\n targetLocale,\n workflowRequest.key,\n );\n const suggestion = await suggestTranslation(provider, workflowRequest, signal, {\n quality: options.quality,\n });\n const id = idFactory();\n\n if (!id.trim()) {\n throw new Error(\"Suggestion IDs must not be empty.\");\n }\n\n const record = immutable({\n id,\n key: suggestion.key,\n locale: suggestion.locale,\n sourceLocale,\n sourceMessage: workflowRequest.sourceMessage,\n value: suggestion.value,\n baseRevision: current?.revision ?? 0,\n status: \"pending\" as const,\n createdAt: timestamp(clock),\n ...(suggestion.quality ? { quality: suggestion.quality } : {}),\n });\n\n await store.createPendingSuggestion(record);\n return record;\n },\n\n async approve(id, reviewer) {\n assertServerOnly();\n const suggestion = await store.getSuggestion(id);\n\n if (!suggestion) {\n throw new Error(`Unknown translation suggestion \"${id}\".`);\n }\n\n return store.approveSuggestion(id, reviewer, suggestion.baseRevision);\n },\n\n reject(id, reviewer, reason) {\n assertServerOnly();\n return store.rejectSuggestion(id, reviewer, reason);\n },\n\n getSuggestion(id) {\n assertServerOnly();\n return store.getSuggestion(id);\n },\n\n getTranslation(locale, key) {\n assertServerOnly();\n return store.getTranslation(locale, key);\n },\n\n listAuditTrail() {\n assertServerOnly();\n return store.listAuditTrail();\n },\n };\n};\n"],"mappings":";;;AAgDA,IAAa,iCAAb,cAAoD,MAAM;CACxD,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAgEA,MAAM,iBAAiB,QAAgB,QACrC,GAAG,OAAO,QAAQ;AAEpB,MAAM,aAAmC,UACvC,OAAO,OAAO,EAAE,GAAG,MAAM,CAAC;AAE5B,MAAM,mBAAmB,aAA6B;CACpD,MAAM,aAAa,SAAS,KAAK;CAEjC,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,kCAAkC;CAGpD,OAAO;AACT;AAEA,MAAM,aAAa,UAA8B,MAAM,CAAC,CAAC,YAAY;AAErE,MAAM,mBAAmB,WAA2B;CAClD,IAAI;EACF,MAAM,CAAC,aAAa,KAAK,oBAAoB,MAAM;EAEnD,IAAI,WACF,OAAO;CAEX,QAAQ,CAER;CAEA,MAAM,IAAIA,iBAAAA,2BACR,kBACA,0BAA0B,OAAO,GACnC;AACF;AAEA,MAAM,yBAA+B;CACnC,IAAI,OAAO,WAAW,aACpB,MAAM,IAAIA,iBAAAA,2BACR,eACA,2EACF;AAEJ;AAEA,MAAa,wCACX,UAAuD,CAAC,MAC7B;CAC3B,MAAM,QAAQ,QAAQ,gCAAgB,IAAI,KAAK;CAC/C,MAAM,+BAAe,IAAI,IAAkC;CAC3D,MAAM,8BAAc,IAAI,IAAqC;CAC7D,MAAM,a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EACzC;EAEA,iBAAiB;GACf,iBAAiB;GACjB,OAAO,MAAM,eAAe;EAC9B;CACF;AACF"}
@@ -0,0 +1,91 @@
1
+ import { SuggestTranslationOptions, TranslationQualityReport, TranslationSuggestionProvider, TranslationSuggestionRequest } from "./index.cjs";
2
+ export type TranslationReviewStatus = "pending" | "approved" | "rejected";
3
+ export interface VersionedTranslation {
4
+ readonly key: string;
5
+ readonly locale: string;
6
+ readonly value: string;
7
+ readonly revision: number;
8
+ }
9
+ export interface TranslationReviewRecord {
10
+ readonly id: string;
11
+ readonly key: string;
12
+ readonly locale: string;
13
+ readonly sourceLocale: string;
14
+ readonly sourceMessage: string;
15
+ readonly value: string;
16
+ readonly baseRevision: number;
17
+ readonly status: TranslationReviewStatus;
18
+ readonly createdAt: string;
19
+ readonly quality?: TranslationQualityReport;
20
+ readonly reviewedAt?: string;
21
+ readonly reviewedBy?: string;
22
+ readonly rejectionReason?: string;
23
+ }
24
+ export interface TranslationReviewAuditRecord {
25
+ readonly suggestionId: string;
26
+ readonly key: string;
27
+ readonly locale: string;
28
+ readonly action: "suggested" | "approved" | "rejected";
29
+ readonly actor: string;
30
+ readonly at: string;
31
+ readonly previousRevision: number;
32
+ readonly revision: number;
33
+ readonly previousValue?: string;
34
+ readonly value: string;
35
+ readonly reason?: string;
36
+ }
37
+ export declare class TranslationReviewConflictError extends Error {
38
+ constructor(message: string);
39
+ }
40
+ export interface TranslationReviewStore {
41
+ getTranslation(locale: string, key: string): Promise<VersionedTranslation | undefined>;
42
+ getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;
43
+ createPendingSuggestion(record: TranslationReviewRecord): Promise<void>;
44
+ approveSuggestion(id: string, reviewer: string, expectedRevision: number): Promise<{
45
+ suggestion: TranslationReviewRecord;
46
+ translation: VersionedTranslation;
47
+ }>;
48
+ rejectSuggestion(id: string, reviewer: string, reason?: string): Promise<TranslationReviewRecord>;
49
+ listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;
50
+ }
51
+ export interface TransactionalTranslationReviewTransaction {
52
+ getTranslation(locale: string, key: string): Promise<VersionedTranslation | undefined>;
53
+ getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;
54
+ /** Atomically inserts the record only when its ID is unused. */
55
+ insertSuggestionIfAbsent(record: TranslationReviewRecord): Promise<boolean>;
56
+ /** Atomically updates the record only while its stored status is pending. */
57
+ updateSuggestionIfPending(id: string, record: TranslationReviewRecord): Promise<boolean>;
58
+ /** Atomically writes only when the current revision equals expectedRevision. */
59
+ compareAndSetTranslation(locale: string, key: string, expectedRevision: number, translation: VersionedTranslation): Promise<boolean>;
60
+ appendAuditRecord(record: TranslationReviewAuditRecord): Promise<void>;
61
+ listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;
62
+ }
63
+ export interface TransactionalTranslationReviewPersistence {
64
+ /** Commits all callback writes together and rolls them back if it throws. */
65
+ transaction<Result>(operation: (transaction: TransactionalTranslationReviewTransaction) => Promise<Result>): Promise<Result>;
66
+ }
67
+ export interface CreateInMemoryTranslationReviewStoreOptions {
68
+ clock?: () => Date;
69
+ }
70
+ export declare const createInMemoryTranslationReviewStore: (options?: CreateInMemoryTranslationReviewStoreOptions) => TranslationReviewStore;
71
+ export interface CreateTransactionalTranslationReviewStoreOptions {
72
+ clock?: () => Date;
73
+ }
74
+ export declare const createTransactionalTranslationReviewStore: (persistence: TransactionalTranslationReviewPersistence, options?: CreateTransactionalTranslationReviewStoreOptions) => TranslationReviewStore;
75
+ export interface CreateTranslationReviewWorkflowOptions {
76
+ idFactory?: () => string;
77
+ clock?: () => Date;
78
+ quality?: SuggestTranslationOptions["quality"];
79
+ }
80
+ export interface TranslationReviewWorkflow {
81
+ suggest(request: TranslationSuggestionRequest, signal?: AbortSignal): Promise<TranslationReviewRecord>;
82
+ approve(id: string, reviewer: string): Promise<{
83
+ suggestion: TranslationReviewRecord;
84
+ translation: VersionedTranslation;
85
+ }>;
86
+ reject(id: string, reviewer: string, reason?: string): Promise<TranslationReviewRecord>;
87
+ getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;
88
+ getTranslation(locale: string, key: string): Promise<VersionedTranslation | undefined>;
89
+ listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;
90
+ }
91
+ export declare const createTranslationReviewWorkflow: (provider: TranslationSuggestionProvider, store: TranslationReviewStore, options?: CreateTranslationReviewWorkflowOptions) => TranslationReviewWorkflow;
@@ -0,0 +1,91 @@
1
+ import { SuggestTranslationOptions, TranslationQualityReport, TranslationSuggestionProvider, TranslationSuggestionRequest } from "./index.js";
2
+ export type TranslationReviewStatus = "pending" | "approved" | "rejected";
3
+ export interface VersionedTranslation {
4
+ readonly key: string;
5
+ readonly locale: string;
6
+ readonly value: string;
7
+ readonly revision: number;
8
+ }
9
+ export interface TranslationReviewRecord {
10
+ readonly id: string;
11
+ readonly key: string;
12
+ readonly locale: string;
13
+ readonly sourceLocale: string;
14
+ readonly sourceMessage: string;
15
+ readonly value: string;
16
+ readonly baseRevision: number;
17
+ readonly status: TranslationReviewStatus;
18
+ readonly createdAt: string;
19
+ readonly quality?: TranslationQualityReport;
20
+ readonly reviewedAt?: string;
21
+ readonly reviewedBy?: string;
22
+ readonly rejectionReason?: string;
23
+ }
24
+ export interface TranslationReviewAuditRecord {
25
+ readonly suggestionId: string;
26
+ readonly key: string;
27
+ readonly locale: string;
28
+ readonly action: "suggested" | "approved" | "rejected";
29
+ readonly actor: string;
30
+ readonly at: string;
31
+ readonly previousRevision: number;
32
+ readonly revision: number;
33
+ readonly previousValue?: string;
34
+ readonly value: string;
35
+ readonly reason?: string;
36
+ }
37
+ export declare class TranslationReviewConflictError extends Error {
38
+ constructor(message: string);
39
+ }
40
+ export interface TranslationReviewStore {
41
+ getTranslation(locale: string, key: string): Promise<VersionedTranslation | undefined>;
42
+ getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;
43
+ createPendingSuggestion(record: TranslationReviewRecord): Promise<void>;
44
+ approveSuggestion(id: string, reviewer: string, expectedRevision: number): Promise<{
45
+ suggestion: TranslationReviewRecord;
46
+ translation: VersionedTranslation;
47
+ }>;
48
+ rejectSuggestion(id: string, reviewer: string, reason?: string): Promise<TranslationReviewRecord>;
49
+ listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;
50
+ }
51
+ export interface TransactionalTranslationReviewTransaction {
52
+ getTranslation(locale: string, key: string): Promise<VersionedTranslation | undefined>;
53
+ getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;
54
+ /** Atomically inserts the record only when its ID is unused. */
55
+ insertSuggestionIfAbsent(record: TranslationReviewRecord): Promise<boolean>;
56
+ /** Atomically updates the record only while its stored status is pending. */
57
+ updateSuggestionIfPending(id: string, record: TranslationReviewRecord): Promise<boolean>;
58
+ /** Atomically writes only when the current revision equals expectedRevision. */
59
+ compareAndSetTranslation(locale: string, key: string, expectedRevision: number, translation: VersionedTranslation): Promise<boolean>;
60
+ appendAuditRecord(record: TranslationReviewAuditRecord): Promise<void>;
61
+ listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;
62
+ }
63
+ export interface TransactionalTranslationReviewPersistence {
64
+ /** Commits all callback writes together and rolls them back if it throws. */
65
+ transaction<Result>(operation: (transaction: TransactionalTranslationReviewTransaction) => Promise<Result>): Promise<Result>;
66
+ }
67
+ export interface CreateInMemoryTranslationReviewStoreOptions {
68
+ clock?: () => Date;
69
+ }
70
+ export declare const createInMemoryTranslationReviewStore: (options?: CreateInMemoryTranslationReviewStoreOptions) => TranslationReviewStore;
71
+ export interface CreateTransactionalTranslationReviewStoreOptions {
72
+ clock?: () => Date;
73
+ }
74
+ export declare const createTransactionalTranslationReviewStore: (persistence: TransactionalTranslationReviewPersistence, options?: CreateTransactionalTranslationReviewStoreOptions) => TranslationReviewStore;
75
+ export interface CreateTranslationReviewWorkflowOptions {
76
+ idFactory?: () => string;
77
+ clock?: () => Date;
78
+ quality?: SuggestTranslationOptions["quality"];
79
+ }
80
+ export interface TranslationReviewWorkflow {
81
+ suggest(request: TranslationSuggestionRequest, signal?: AbortSignal): Promise<TranslationReviewRecord>;
82
+ approve(id: string, reviewer: string): Promise<{
83
+ suggestion: TranslationReviewRecord;
84
+ translation: VersionedTranslation;
85
+ }>;
86
+ reject(id: string, reviewer: string, reason?: string): Promise<TranslationReviewRecord>;
87
+ getSuggestion(id: string): Promise<TranslationReviewRecord | undefined>;
88
+ getTranslation(locale: string, key: string): Promise<VersionedTranslation | undefined>;
89
+ listAuditTrail(): Promise<readonly TranslationReviewAuditRecord[]>;
90
+ }
91
+ export declare const createTranslationReviewWorkflow: (provider: TranslationSuggestionProvider, store: TranslationReviewStore, options?: CreateTranslationReviewWorkflowOptions) => TranslationReviewWorkflow;