Skip to content

[Creem Catalog 1/3] 价格级映射持久化 + 安全绑定已有商品 #155

Closed

Description

@fxbin

Parent: #154
Depends on: #58 (issue-first contract)

目标

建立MonetPlane Price → Creem Product 的受控、价格级持久映射,并在控制台提供「绑定已有 Creem 商品」能力。给下一阶段自动创建商品提供稳定的数据层。当前源数据为 provider_connections.metadata.catalog[priceId],不得通过人工 SQL 直接改生产映射。

范围

  1. 设计持久化映射(优先独立 provider_catalog_mappings / 相应迁移;如不引入新表,须给出同等的唯一性、环境隔离、恢复和演进证据):
    • applicationId、providerConnectionId、environment、monetplanePriceId、providerProductId、source(linked/created)、状态及审计关联;
    • applicationId+environment+providerConnectionId+priceId 唯一,冲突安全;禁止一条 Price 静默重绑到不同 Creem 商品;
    • 不在映射中存储 Creem API Key / Webhook Secret;
    • DB constraints 与 service 层双重校验同一 Application、环境和连接启用状态。
  2. Creem read adapter 支持 GET /v1/products?product_id=...,从已有连接的 服务端解密 API Key 查询,严格按连接 mode 选择 Test/Production API Base。
  3. 创建受权的管理命令 / API:通过 requirePermission('catalog:write') + requireApplicationAccess、显式环境验证完成 link;校验返回产品 id、mode、status、currency、price 最小单位、onetime|recurring、billing_period 与 MonetPlane Price 完全匹配;不匹配 fail closed,返回可诊断错误(不泄露凭证)。
  4. 兼容性:既有 provider_connections.metadata.catalog 中的映射必须在过渡期正常供 Checkout 读取;明确 backfill/优先级/冲突策略及升级回滚边界。禁止迁移直接丢弃旧 metadata。
  5. 在现有控制台提供最小的「关联已有」入口:选 Price、粘贴 Creem Product ID、先只读验证、确认后绑定。展示只读校验结果,不提供盲目写入。
  6. 记录映射创建 / 冲突 / 拒绝 / 更新的 operator audit,避免泄露 Secret。

验收标准

  • 实际存在的 Creem Sandbox 商品可以绑定到同 Application 的一次性 USD Price;返回 Product ID、模式、价格与保存的映射一致。
  • 相同映射的重复请求幂等,竞争请求唯一;不同映射不能静默覆盖。
  • 跨 Application、Test→Live、伪造/不存在商品、下架、金额/币种/周期不一致全部拒绝且无持久映射。
  • 旧连接 metadata 的 checkout 行为保持不变;迁移覆盖 fresh DB、重复执行、从已部署版本升级,并测试新旧映射不一致时安全拒绝。
  • 未授权 operator / 受限 application scope 无权绑定;业务 mp_app_* 不能使用该管理接口。
  • 单元/集成测试覆盖真实 handler、adapter mock、权限与并发;生产 DB 不用于集成测试。
  • pnpm lint && pnpm typecheck && pnpm test && pnpm test:integration && pnpm build 全绿;migration gates 全绿。

实现边界与参考

  • src/modules/providers/{schema.ts,service.ts,adapters/creem.ts}
  • src/modules/catalog/{schema.ts,service.ts}
  • src/server/control-plane/products.ts
  • src/app/api/admin/** & src/components/**
  • Creem API reference
  • 公开 issue / PR 中不出现任何私有部署域名、真实商户密钥、现有生产 Product / Price / Connection ID。
  • 遵循 [Process] Issue-first execution contract for local coding agents #58,每次只处理本 Issue 对应 PR。

Activity

  1. added a commit that references this issue on Oct 8, 2026
  2. reopened this on Oct 8, 2026
  3. fxbin commented on Oct 8, 2026

    @fxbin
    OwnerAuthor

    Reopened to keep the external-evidence gate open per #58 §11: the real Creem Sandbox bind (acceptance criterion 1) is still pending — it closes via #157's Path A end-to-end gate or operator-recorded Sandbox evidence. Code path landed in #158 (merged); this issue tracks the remaining evidence.

  4. fxbin commented on Oct 11, 2026

    @fxbin
    OwnerAuthor

    #155 acceptance sign-off — operator Sandbox evidence + merged regression suite

    Evidence reviewed: #157 real Creem Test acceptance report, Gate 1 Path A: pre-existing Test Product (USD 19.00, one-time) → Console read-only Verify → audited Link existing → persisted linked/synced with matching product id; SDK mp_app_* Checkout later resolved that mapping and created checkout (201). Provider ID was not inferred from mock data. The report is operator-attested external evidence, not an independently replayed payment/provider session.

    Code baseline: PR #158 merged e92db153...; regression tests in tests/integration/provider-catalog-links.test.ts cover idempotent duplicate bind, conflicting bind refusal, mismatched currency, inactive/mode mismatch, non-existing product, legacy conflicts, cross-application/connection/environment, revoked connection, permissions, and persisted mapping checkout precedence. DB uniqueness, old metadata fallback and migration/repeatability gates were previously reviewed in the PR. Main includes #158/#159/#160; no new production deployment.

    Decision: #155's remaining explicit real-Sandbox binding gate is satisfied by Gate 1 in the operator report, combined with the merged code/CI and integration suite. This approval is limited to #155. The broader #157 end-to-end Sandbox checklist and production release gate are not implied complete. No credentials or private endpoints in this note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions