Skip to content

feat(auth/i18n): 手机短信文案国际化(模板可定制 + 内置中英,#2815)#2826

Merged
os-zhuang merged 2 commits into
mainfrom
claude/sms-infrastructure-phone-otp-9tisdu
Jul 11, 2026
Merged

feat(auth/i18n): 手机短信文案国际化(模板可定制 + 内置中英,#2815)#2826
os-zhuang merged 2 commits into
mainfrom
claude/sms-infrastructure-phone-otp-9tisdu

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Closes #2815

#2780 的 OTP / 邀请短信正文是英文硬编码。本 PR 实现两层解析:

方案(issue 里的首选路线:复用 sys_notification_template

  1. 租户可定制模板(topic: auth.phone_otp | auth.phone_invite, channel: 'sms', locale)sys_notification_template 行——与 messaging sms channel 同一对象、同一 locale fallback 语义(zh-CN → zh → en),可在 Setup 中编辑。AuthPlugin 在 kernel:ready(phone 登录开启时)seed 内置中英四行,只在缺失时插入,租户定制(含停用)永不覆盖。
  2. 内置双语兜底:无模板行(新环境/表未建/冷门 locale)时使用打包的 en/zh 文案。

关键决策

  • locale 来源 = 部署默认localization.locale 设置,live 重绑定):sys_user 目前没有 locale 字段,按用户 locale 解析留待该字段落地后跟进(已在 feat(sms/i18n): 邀请/OTP 短信文案国际化(按用户 locale 渲染) #2815 注明)。这已解决核心痛点——中文部署统一收中文短信。
  • OTP 文案改为用途中性(不再区分 sign-in/reset 措辞):一个报备模板同时覆盖两个流程,且短信不泄露验证码用途——对阿里云模板制也更友好(issue 里的 per-locale TemplateCode 映射由此消解为运营侧单模板语言选择)。
  • 插值器与 messaging 渲染器同语义{{ hole }},单遍、无逻辑),本地 20 行实现——plugin-auth 不新增对 service-messaging 的依赖。
  • 红线不变:模板读取 best-effort(任何异常回退内置文案,绝不阻塞 OTP 发送);OTP 码仍只出现在短信正文。

测试

plugin-auth 全套 385 通过(新增 15 个:locale 链、内置双语完整性、插值、模板加载 fallback、seed 幂等与失败隔离、zh-CN 部署 OTP/邀请中文渲染、租户模板覆盖、模板故障回退)。

🤖 Generated with Claude Code

https://claude.ai/code/session_013LXUXU66dBaP3SSG4ZVtuH


Generated by Claude Code

- phone-sms-texts.ts: built-in en/zh bodies for auth.phone_otp /
  auth.phone_invite, {{hole}} interpolation (same semantics as the
  messaging renderer, kept dependency-free), locale chain
  (zh-CN -> zh -> en), best-effort sys_notification_template loader, and
  an insert-if-missing seeder (tenant edits never overwritten)
- auth-manager: deliverPhoneOtp/sendPhoneInviteSms render through the
  template-then-builtin resolution; setDefaultSmsLocale() mirrors
  setAppName(); OTP wording is now purpose-neutral (one provider template
  covers sign-in and reset; the SMS reveals nothing about what the code
  unlocks)
- auth-plugin: binds localization.locale (live re-bind on settings
  changes) and seeds the built-in template rows at kernel:ready when
  phone sign-in is enabled

Template lookups are best-effort - an outage never blocks an OTP send.
No-OTP-in-logs red line unchanged.

Closes #2815

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013LXUXU66dBaP3SSG4ZVtuH
@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Canceled Canceled Jul 11, 2026 3:28am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-auth.

9 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/deployment/production-readiness.mdx (via @objectstack/plugin-auth)
  • content/docs/getting-started/cli.mdx (via @objectstack/plugin-auth)
  • content/docs/kernel/services-checklist.mdx (via @objectstack/plugin-auth)
  • content/docs/permissions/authentication.mdx (via @objectstack/plugin-auth)
  • content/docs/permissions/sso.mdx (via @objectstack/plugin-auth)
  • content/docs/plugins/index.mdx (via @objectstack/plugin-auth)
  • content/docs/plugins/packages.mdx (via @objectstack/plugin-auth)
  • content/docs/releases/implementation-status.mdx (via @objectstack/plugin-auth)
  • content/docs/releases/v9.mdx (via @objectstack/plugin-auth)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling labels Jul 11, 2026
@github-actions github-actions Bot added size/l and removed size/m labels Jul 11, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review July 11, 2026 03:29
@os-zhuang
os-zhuang merged commit e2c05d6 into main Jul 11, 2026
16 checks passed
@os-zhuang
os-zhuang deleted the claude/sms-infrastructure-phone-otp-9tisdu branch July 11, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sms/i18n): 邀请/OTP 短信文案国际化(按用户 locale 渲染)

2 participants