finance: Shopee adapter S1, signer, token, shop info and orders read, dormant (#2524, #4274) #4277
All Vouch review confidence checks passed
Residual risk 0.48 = Change Risk (0.75) × (1 − Review Confidence (0.36)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 68% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #4277"
general
weight: 0.35
claude[bot]
Closes #4274
Summary
First slice of the Shopee adapter (#2524), built from the official Open Platform docs read on 2026-11-21 (design note, PO decisions in the next comment). Dormant: nothing offers
shopeeuntil the live check (#2522); no migration, no table, no UI.marketplace-shopee-sign.ts: signer (HMAC-SHA256 over partner id + path + timestamp [+ token + shop id]); vectors checked against openssl.marketplace-shopee-token.ts: token create andShopeeRefresher(providermarketplace_shopee, 30 min horizon). The refresh token is single use and replaced each refresh; one call, never repeated; refusal only by dates; unreadable verdicts not re-asked for 30 min.marketplace-shopee.ts: the one signed caller (partner.shopeemobile.com), paced 1 call/s per partner and shop, error words to the port's kinds, shop info (also gives the authorization end), connection test.marketplace-shopee-orders.ts:get_order_listby update time +get_order_detailin batches of 50, no buyer field requested, amounts kept as exact JSON source text (context.source), stage table, stock rule (system/Ops cancellation after pickup staysshipped), cursor with window end and width.MARKETPLACE_PROVIDERSnamesshopee;shopeeadded toMARKETPLACE_ADAPTERS.New finding from the API pages: only the ERP System and Seller In-house System app types can call order list, returns, escrow and shop info together (Accounting and Finance cannot read the order list).
Acceptance
marketplace-shopee-token.test.ts(local run: 45 tests pass across the two new test files).channel-refresh.db.test.tsShopee block (DB test not run locally, CI only).4503599627370497.5kept;3 x 0.1 = 0.3; exponent, >4 decimals, negative refused.decimal.js, floats never JS numbers; performance: at most 7 list + 2 detail calls per poll, paced; accessibility: n/a.pnpm lint,pnpm --filter @crove/kernel typecheck,@crove/mod-financetypecheck,docs:checkpass locally.Review
Codex is not installed in this environment (not run). A fresh-context reviewer found no blocking issue; taken: unnamed canceller after pickup stays
shipped, throttle words no longer shadow unreadable ones, shop id capped at 15 digits (exact in JSON number), first window one second inside the 15-day limit, pacing aligned with the port's 60/min. Not taken (non-blocking): overlap counted inside narrow widths, a permanently missing detail entry stalls loudly (deliberate "never skip"), unknown error words read asunreachable.Risk left: all words and stages are the code's reading of the docs until the live check (#2522); bundle-deal lines use the original price (order money is the escrow's job, S3).
---
_Generated by Claude Code_
---
<!-- dos-pr-summary -->
📌 TL;DR
This PR introduces the Shopee marketplace integration (S1 slice), implementing the API caller, HMAC-SHA256 signing, token management (with single-use refresh token rotation), and a read-only orders adapter with a sophisticated cursor-based pagination strategy. It also registers the
ShopeeRefresherin the kernel's channel refresh sweep and adds comprehensive integration tests.🎯 Type of Change
🔍 Changes Walkthrough
| File | Summary of Changes |
| :--- | :--- |
|
apps/kernel/src/kernel.ts| Registers theShopeeRefresherin thechannelRefreshersfactory when theshopeeprovider is configured, enabling automatic token renewal via the worker sweep. ||
apps/kernel/src/marketplace-shopee-sign.ts| New. Implements the pure functionsignShopeeRequestwhich generates the HMAC-SHA256 signature required by Shopee's Open API v2, handling both public and shop-scoped calls. ||
apps/kernel/src/marketplace-shopee-token.ts| New. Implements the token lifecycle:createShopeeToken(trading auth codes for tokens) and theShopeeRefresherclass. Handles single-use refresh token rotation, expiration checks, and in-memory verdict caching to prevent redundant API calls. ||
apps/kernel/src/marketplace-shopee.ts| New. The core API caller (shopeeCaller) with rate limiting (turn-taking per partner/shop), error classification, and thetestShopeeConnectionlogic. IncludesparseShopeeSecretfor credential validation. ||
apps/kernel/src/marketplace-shopee-orders.ts| New. The orders adapter implementingMarketplaceProvider. Features a complex cursor-based pagination system that adapts window sizes (15d → 1min) to handle rate limits and data density, along with strict data validation and stock-stage mapping logic. ||
apps/kernel/test/channel-refresh.db.test.ts| Adds integration tests for the Shopee refresher within the PostgreSQL-backed channel refresh sweep, verifying token rotation, concurrency safety, and expiration handling. ||
apps/kernel/test/fake-shopee.ts| New. An in-process mockfetchimplementation that simulates the Shopee API, including signature verification and token state management, for use in tests. |📊 Architectural Flow
<!-- /dos-pr-summary -->